我需要清除遠程服務器上的文件夾,然後再向其中複製新文件。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
誰能告訴我我要去哪裏錯了?