我需要先清除远程服务器上的文件夹,然后再将新文件复制到该文件夹。
所以我客户端上的脚本包含以下内容:
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 上查找了这个,我的理解是,如果服务器使用代理(我在尝试访问 Internet 时使用代理),那么我需要使用 $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
谁能告诉我哪里出错了?