0
votes

I am trying to list all the websites in IIS on a remote server using PowerShell scripting. Below is how I am trying to connect to the server:

$s = New-PSSession -ComputerName $Server

But when I run the script I am getting the following error:

New-PSSession : [Server] Connecting to remote server Server failed with the
following error message : WinRM cannot process the request. The following error
occurred while using Kerberos authentication: Cannot find the computer Server.
Verify that the computer exists on the network and that the name provided is
spelled correctly. For more information, see the about_Remote_Troubleshooting
Help topic.
At C:\AppServers\Application.ps1:8 char:8
+         $s = New-PSSession -ComputerName Server
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionOpenFailed

The server is already enabled to receive remote requests.

Update:

Below is the full function that i am trying to run:

function audit-servers {  
if (Test-path "ApplicationsOnTheServer.txt") {Remove-Item "ApplicationsOnTheServer.txt"}
if (Test-Path "ServersList.txt") {
foreach ($server in Get-Content .\ServersList.txt) {

    "Application Server : $server`n" | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
    "Applications list:" | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
    $s = New-PSSession -ComputerName $server -Credential domainabc\myname
    Invoke-Command -Session $s -ScriptBlock {Import-Module WebAdministration;Get-iissite} | out-file -FilePath "ApplicationsOnTheServer.txt" -Append
}
} else {
    "ServersList.txt file is missing"
     break;
}
"`nAll Done!`n"}

The ServersList.txt has atstappvmabc.tsteag.com

3
Try to pass the Credential parameter along with a domain user to New-PSSession. Passing Credentials (even if basically using the same user) might resolve the Kerberos issue. - Sage Pourpre
Error message clearly stated that you passed Server instead of $Server to -ComputerName which is incorrect unless the name of your server is literally Server. If after correcting that you still receives an error, it will be different than what you pasted in your question. - Robert Dyjas
I tried Credential parameter and tried with domain name as well with no success. - suprasad

3 Answers

1
votes

The error message clearly states that you wanted to connect to the server named Server not to the server which name is stored in $Server variable (text in bold is actually the name of the server you try to connect to):

New-PSSession : [Server] Connecting to remote server Server failed

If you tried to connect to the server named for example MyServer01.example.com you'd receive the error like below (truncated):

PS C:\> New-PSSession -ComputerName "MyServer01.example.com"

New-PSSession : [MyServer01.example.com] Connecting to remote server MyServer01.example.com failed (...)

Even though you state that you try to execute

$s = New-PSSession -ComputerName $Server

You actually execute (notice missing dollar sign)

$s = New-PSSession -ComputerName Server

The above was also taken from the error message you pasted. I'd suggest to first skip the variable and try to enter server path in the command itself to verify it's working:

$s = New-PSSession -ComputerName "MyServer01.example.com"

And then, if it works, put the path in variable and test again.

0
votes

The error you're receiving FullyQualifiedErrorId : NetworkPathNotFound generally means that the name you're passing to the -ComputerName parameter can't be resolved.

Perhaps try running Test-Connection $Server to troubleshoot what's happening there.

0
votes

Your variable $Server contains wrong value. You have to assign valid computer name to $Server.