【发布时间】:2017-02-08 15:35:22
【问题描述】:
我已经实现了一个 PS 脚本,可以同时在多个服务器上部署代码。在这里,我需要将一些源文件从一台服务器复制到另一台服务器。请看下面的代码:
for ($i=1; $i -le 5; $i++) {
$serverName="iwflO" + $i
$sourceFile="\\iwdflO1\C$\Deploy\bin"
$destination="\\$serverName\C$\Program Files (X86)\Shian\MyService\bin\"
$Myblock = {
Param{$sourceFile,$destination)
Copy-Item -Force -Recurse $sourceFile -Destination $destination
}
$result = Invoke-Command -ComputerName $ServerName -Credential "shian" -ScriptBlock $Myblock -ArgumentList $sourceFile,$destination;
$result;
}
cd c:\
iwflO1 运行良好,它是我运行脚本的根服务器,但对于其他服务器,它给了我类似的错误
找不到路径“\iwdflO1\C$\Deploy\bin”,因为它不存在。
但如果我登录到 iwflO2 或任何其他服务器并手动点击路径,它工作正常。
【问题讨论】:
-
这看起来像是双跳问题。这是一个technet blog,有一些变通方法。
-
看看这个看看是不是类似stackoverflow.com/a/23625969/5233410
-
Ben 怎么会出现双跳问题?
-
@RanadipDutta localhost ->
Invoke-Command-> 第一跳 -> UNC 路径 -> 第二跳 -
我真的不认为它在逻辑上实际上是双重希望。理论上是的。双跳通常意味着从远程计算机跳转到另一台计算机(主要使用 Invoke 和 pssession)。在这里它直接与管理员共享。无论如何,我支持你@AnsgarWiechers。 :)
标签: powershell powershell-2.0 powershell-3.0 powershell-4.0 powershell-remoting