我正在尝试使用本地 powershell 会话连接到远程计算机。
为此,我尝试使用本地 powershell Enter-PSSession 或 New-PSSession 命令作为:
$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# 打开运行空间并向 WSManConnectionInfo 对象提供远程服务器 powerSell url 时,也发生了同样的异常。
我已经尝试了所有与 winrm 命令相关的方法,但这并没有真正解决问题。如何摆脱这个问题?
答案1
为什么不简单呢Enter-PSSession apdv0710.forest7.dom
?
您需要Enable-PSRemoting
首先在 apdv0710.forest7.dom 上运行。
答案2
这对我有用,因为只提供了计算机名称、Kerberos 作为身份验证机制以及包含用户名和密码的凭证对象。
New-PSSession -Authentication Kerberos -Computer 'apdv004s' -Cred $credential
用法相同Enter-PSSession
。