如何使用Powershell从本地连接到远程服务器 Enter-PSSession不起作用

问题描述

我正在尝试使用本地Powershell会话连接到远程计算机。

为此,我尝试将本地Powershell Enter-PSSessionNew-PSSession comandlet用作:

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

但是在例外之后,我一直很忙。

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
@R_468_4045@ion,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

我还使用了其他版本:

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 @R_468_4045@ion,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

在大多数情况下,我会遇到第一个例外。

当我使用C#打开运行空间并为WSManConnectionInfo对象提供远程服务器powerSell url时,也会发生同样的异常。

我已经对winrm命令进行了各种尝试,但这并不能真正解决问题。 如何摆脱这个问题?

解决方法

通过提供计算机名,Kerberos作为身份验证机制以及包含用户名和密码的凭据对象,这对我有用。

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

Enter-PSSession的用法相同