powershell脚本将文件从Windows复制到多个Linux系统

时间:2015-05-15 09:21:27

标签: powershell

我正在尝试使用Powershell脚本将文件从Windows复制到多台Linux机器。从txt文件中读取计算机列表。尝试使用pscp进行复制但不起作用。这可能是个问题?有没有更好的方法呢?感谢

$list = Get-Content C:\list.txt

foreach($host in $list) {

  Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw mypasswd C:\patch.sh root@$host:/root/")   

}

1 个答案:

答案 0 :(得分:3)

除了@ obfuscate之外,$host是一个保留的只读变量,由于冒号,您可能会遇到root@$host:/root/的问题。冒号是变量的命名空间标识符。如果您需要使用文字冒号跟随变量,则应使用花括号。

尝试:

$list = Get-Content C:\list.txt

foreach($remotehost in $list) {

  Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' `
      -ArgumentList ("-scp -pw mypasswd C:\patch.sh root@${remotehost}:/root/")   

}