我正在嘗試使用本機 powershell 會話連接到遠端電腦。
為此,我嘗試使用本機 powershell Enter-PSSession 或 New-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
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# 開啟運行空間並提供具有遠端伺服器 powerSell url 的 WSManConnectionInfo 物件時,也會發生相同的異常。
我已經做了有關 winrm 命令的所有方法,但這並不能真正解決問題。如何擺脫這個問題?
答案1
為什麼不簡單一點呢Enter-PSSession apdv0710.forest7.dom
?
您需要Enable-PSRemoting
先在 apdv0710.forest7.dom 上運行。
答案2
這對我有用,僅提供電腦名稱、Kerberos 作為身份驗證機制以及包含使用者名稱和密碼的憑證物件。
New-PSSession -Authentication Kerberos -Computer 'apdv004s' -Cred $credential
與 的用法相同Enter-PSSession
。