[英]PowerShell run bat from location on my computer on remote computer
I need to run a BAT file on some servers Because of the amount of many servers I avoid copying the file on any server 我需要在某些服务器上运行BAT文件由于有许多服务器,因此我避免在任何服务器上复制文件
I have the file on my computer and I try to access it remotely 我的计算机上有文件,我尝试远程访问它
$CMDCOMMAND = "\\Mycomp\c$\file.bat"
Invoke-Command -ComputerName $Hostname -Credential $Cred -ScriptBlock {
Start-Process cmd.exe "/c $CMDCOMMAND
}
Invoke-Command -Computer $Hostname -Credential $Cred -FilePath $CMDCOMMAND
should work as @Ansgar Wiechers mentioned. 应该像@Ansgar Wiechers提到的那样工作。
I doubt you have set $CMDCOMMAND = "\\\\Mycomp\\c$\\file.bat"
and tried. 我怀疑您已设置
$CMDCOMMAND = "\\\\Mycomp\\c$\\file.bat"
并尝试过。 It should be local path when you pass it to -FilePath
传递给
-FilePath
时,它应该是本地路径
$CMDCOMMAND = "c:\file.bat"
Invoke-Command does not work with a variable defined outside the ScriptBlock. Invoke-Command不适用于在ScriptBlock外部定义的变量。 You need to use the ArgumentList parameter.
您需要使用ArgumentList参数。 Something like this should work, although I have not tested it:
像这样的东西应该可以工作,尽管我还没有测试过:
$CMDCOMMAND = "\\Mycomp\c$\file.bat"
Invoke-Command -ComputerName $Hostname -Credential $Cred -ScriptBlock {
param($ARGLIST) Start-Process cmd.exe "/c $ARGLIST"
} -ArgumentList $CMDCOMMAND
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.