Search code examples
powershellpowershell-remoting

How to connect to remote server using powershell from local . Enter-PSSession not working


I am trying to connect to remote computer using local powershell session.

for that I am trying to use local powershell Enter-PSSession or New-PSSession comandlets as :

$session = New-PSSession -ConnectionUri 'http://testserverUri.dom/PowerShell'

But I am getting all the times following exception.

New-PSSession : [testserveruri.dom] Connecting to remote server apdv0710.forest7.dom failed with the following
error message : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was
not available. This is usually returned by a HTTP server that does not support the WS-Management protocol. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = New-PSSession -ConnectionUri 'http://testserverUri.dom/ ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
   gTransportException
    + FullyQualifiedErrorId : URLNotAvailable,PSSessionOpenFailed

I also used other variation :

Enter-PSSession -Authentication Kerberos -ConnectionUri 'http://testserveruri.dom/PowerShell' -Cred $credential
Enter-PSSession : Connecting to remote server apdv0710.forest7.dom failed with the following error message : The WinRM
client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is
usually returned by a HTTP server that does not support the WS-Management protocol. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = Enter-PSSession -Authentication Kerberos -ConnectionUri 'h ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (http://testserveruri.dom/PowerShell:Uri) [Enter-PSSession], PSRemot
   ingTransportException
    + FullyQualifiedErrorId : CreateRemoteRunspaceFailed

In most cases, I am getting the first exception.

This same exception is occuring while I am opening run space using C# and providing WSManConnectionInfo object with remote server powerSell url.

I already did all way arounds regarding winrm commands but this doesn't really solves the issue. How to get rid of this problem?


Solution

  • This worked for me by provided only Computer name, Kerberos as authentication mechnaism in addition with credential object containing user name and password.

    New-PSSession -Authentication Kerberos -Computer 'apdv004s' -Cred $credential 
    

    Same usage for Enter-PSSession