如何从本地使用 powershell 连接到远程服务器。输入-PSSession 不工作

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

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

为此,我正在尝试使用本地 powershell Enter-PSSessionNew-PSSession comandlets 作为 :

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

我还使用了其他变体:

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

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

我在使用 C# 打开 运行 space 并为远程服务器 powerSell url.

提供 WSManConnectionInfo 对象时发生了同样的异常

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

这对我有用,仅提供计算机名称,Kerberos 作为身份验证机制,此外还提供包含用户名和密码的凭据对象。

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

Enter-PSSession

用法相同