-1

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?

Usman
  • 117
  • 6

2 Answers2

1

Why not simply Enter-PSSession apdv0710.forest7.dom?

You need to run Enable-PSRemoting on apdv0710.forest7.dom first.

Daniel
  • 6,780
  • 5
  • 31
  • 60
  • you are right, uri doesnt work. We just need 'Computername' ( e.g. apdv004s ) and Kerberos as authentication type because this is enabled at remote machine should open remote runspace on remote computer. – Usman Aug 28 '20 at 14:02
0

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.

Usman
  • 117
  • 6
  • Some notes: Credentials are only needed if you're authentication as a different user as the one you are runnign enter--pssession with. Kerberos should automatically be negotiated. But sometimes you need to pass that implicitly. kerberos relies on DNS, so the hostname may be in any format that can be resolved to the computers hostname. Or more specifically, to one of the SPNs. – Daniel Aug 28 '20 at 18:11
  • Thanks for comments. – Usman Aug 31 '20 at 07:00