-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?

Panagiotis Kanavos
  • 90,087
  • 9
  • 138
  • 171
Usman
  • 2,426
  • 4
  • 36
  • 68
  • Enter-PSSession is working. The error you posted complains about WinRM's configuration. How was the *server* configured? – Panagiotis Kanavos Aug 28 '20 at 11:51
  • Enter-PSSession works fine for localhost. But I want to connect with remote server and all these problems are occuring for opening runspace / session at remote server. You can see I provided remote server url – Usman Aug 28 '20 at 11:52
  • BTW this is 100% an admin question and should be posted at `serverfault.com` – Panagiotis Kanavos Aug 28 '20 at 11:52
  • Enter-PSSession works fine for remote sessions too. I'm using it for just that. You're asking people to guess how the remote server was configured. Have you tried googling that error message? What is the remote machine's OS version? – Panagiotis Kanavos Aug 28 '20 at 11:53
  • Okay, can you please point by above exceptions, how remote server configured? what can be done at remote server so that it can start listening the requests without above issues? – Usman Aug 28 '20 at 11:57
  • If you google the error message you'll find a *lot* of hits - many results are about connections to Exchange, in which case [Exchange's troubleshooter](https://docs.microsoft.com/en-us/exchange/troubleshoot/administration/connecting-remote-server-failed) can help. In other cases it's a mixup in the IPv4/IPv6 configuration. Sometimes this may be caused when trying to connect from a modern computer to old servers that didn't have IPv6 configured. People can't guess how your server or server is configured. – Panagiotis Kanavos Aug 28 '20 at 11:59
  • I have windows server 2019 as remote server – Usman Aug 28 '20 at 12:00
  • Again, and again, this is a *administration question*, not suitable for SO. Again, did you try googling the error? You may find the exact issue involved and the steps to fix it – Panagiotis Kanavos Aug 28 '20 at 12:00
  • [Searching at serverfault.com](https://serverfault.com/search?q=The+WinRM+client+sent+a+request+to+an+HTTP+server+and+got+a+response+saying+the+requested+HTTP+URL+was+not+available.+) produces 5 answered questions. – Panagiotis Kanavos Aug 28 '20 at 12:02
  • my problem is very simple : Just want to run a script which should change DNS entries in that remote server. So it has nothing to do with Exchange Online or Exchange Server. People are describing above exceptions strictly relating to Exchange Server. But I am not interacting with any Exchange Server. I just want to manipulate DNS Server entries via powershell script – Usman Aug 28 '20 at 12:02
  • No, it's not simple. This isn't about DNS, yes it has everything to do with *remote administration just like that used by Exchange* so you should check those questions that faced the exact same problem. People use WinRM for remote Exchange administration, which is why they mention it when something goes wrong – Panagiotis Kanavos Aug 28 '20 at 12:04
  • does it has something to do with Exchange Mamagement? Exchange Servers? – Usman Aug 28 '20 at 12:05
  • I have a Windows Server 2019 too. I connect to it with `Enter-PSSession` without having to do anything. I didn't disable IPv4. I can't guess what may be wrong with your server – Panagiotis Kanavos Aug 28 '20 at 12:05
  • Does it has something to di with Exchange Server? or with Exchange Environment? – Usman Aug 28 '20 at 12:07
  • 1
  • Go to your Server and try `Enter-PSSession 127.0.0.1` does that work? – T-Me Aug 28 '20 at 12:38
  • yes, this works. It immediately prompts up next line as [127.0.0.1]: PS C:\Windows\system32> – Usman Aug 28 '20 at 13:00
  • Winrm need to be setup and configured – Mahmood Shehab Aug 31 '20 at 15:19

1 Answers1

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
  • 2,426
  • 4
  • 36
  • 68