2012-07-30 49 views
0

我需要清除遠程服務器上的文件夾,然後再向其中複製新文件。Powershell通過代理調用遠程

所以我的客戶端腳本包含以下內容:

Invoke-Command -Computer $TargetServer -ScriptBlock { Remove-Item $ClearPath } 

當我運行此我得到以下錯誤:

Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests 

我看這件事TechNet上的,我從這個理解是如果服務器使用代理(我試圖訪問互聯網時做的),那麼我需要使用$ PSSessionOption對象。所以我改變了我的劇本,這樣下首先執行:

$User = "group\tfs_service" 
$Password = ConvertTo-SecureString -String "x" -AsPlainText -Force 
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Password 
$PSSessionOption = New-PSSessionOption -ProxyAccessType IEConfig -ProxyAuthentication Negotiate -ProxyCredential $Credential 

現在,當我運行該腳本,我得到以下錯誤:

Connecting to remote server failed with the following error message : The WinRM client cannot process the request. Setting proxy information is not valid when the HTTP transport is specified. Remove the proxy information or change the transport and try the request again 

誰能告訴我我要去哪裏錯了?

回答

0

看來我正在吠叫錯誤的樹思維我需要配置代理。唯一的問題是我沒有在遠程服務器上啓用powershell遠程處理。我是能夠通過在升高的的powershell窗口執行以下命令來做到這一點:

Enable-PSRemoting 
1

所述的powershell客戶和遠程的powershell服務器之間的通信必須保持安全的由代理以避免竊聽(=人在中間人),這就是爲什麼只有在傳輸是HTTPS的情況下,Powershell遠程處理才支持代理。

此博客文章How To Use WSMan Proxy Support顯示瞭如何設置服務器端HTTPS偵聽器以及如何通過代理連接到此偵聽器。

一旦服務器端HTTPS監聽器已經安裝,請嘗試從客戶端調用你的腳本塊這樣的:

Invoke-Command -Computer $TargetServer -ScriptBlock { Remove-Item $ClearPath } -sessionoption $PSSessionOption -UseSSL Authentication Basic -Credential $Credential 
0

你嘗試在其他服務器上運行WinRM的quickconfig? 這將配置腳本定位的winrm監聽器

相關問題