2012-07-30 48 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监听器

相关问题