Powershell
如何從本地使用 powershell 連接到遠端伺服器。Enter-PSSession 不工作(不相關的 Exchange 服務)
我正在嘗試使用本地 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 命令進行了各種處理,但這並不能真正解決問題。如何擺脫這個問題?
這對我有用,只提供電腦名稱、Kerberos 作為身份驗證機制以及包含使用者名和密碼的憑據對象。
New-PSSession -Authentication Kerberos -Computer 'apdv004s' -Cred $credential
相同的用法
Enter-PSSession
。
為什麼不簡單
Enter-PSSession apdv0710.forest7.dom
呢?您需要先
Enable-PSRemoting
在 apdv0710.forest7.dom 上執行。