我正在尝试让以下内容工作,以便我可以自动完成我需要执行的一些SCP上传。我认为问题在于如何解释${user}@${device}
。
$user = "user1"
$device = "server1"
Start-Process 'C:\Program Files\PuTTY\pscp.exe' `
-ArgumentList ("c:\temp\myfile.txt ${user}@${device}:/shared/tmp/") -NoNewWindow
我已经尝试$user@$device
(powershell咆哮语法),$user@${device}
和${user}@${device}
(这些告诉我你不能从本地复制到本地,这表明没有解析:/shared/tmp/
正确。)
答案 0 :(得分:1)
您还可以使用:
转义`
:
"c:\temp\myfile.txt ${user}@${device}`:/shared/tmp/"
答案 1 :(得分:0)
试试这个:
$user = "user1"
$device = "server1"
Start-Process 'C:\Program Files\PuTTY\pscp.exe' `
-ArgumentList ("c:\temp\myfile.txt {$($user)}@{$($device)}:/shared/tmp/") -NoNewWindow
答案 2 :(得分:0)
试试这个:
$user = "user1"
$device = "server1"
$Program='C:\Program Files\PuTTY\pscp.exe'
$Arguments="c:\temp\myfile.txt {0}@{1}:/shared/tmp/ -NoNewWindow" -f $user, $device
Start-Process $Program $Arguments
答案 3 :(得分:0)
与往常一样,除非您有使用Start-Process
的具体原因:不要打扰。请改用call operator(&
)。
当我测试它时,这完全没问题:
$user = 'user1'
$device = 'server1'
$params = 'c:\temp\myfile.txt', "${user}@${device}:/shared/tmp/"
& 'C:\Program Files\PuTTY\pscp.exe' @params