$remoteinst = "\Windows\Temp\MyFolder"
$remotecomp = ComputerName
$remotesess = New-PSSession $remotecomp
$remotedir = "C:" + $remoteinst + "\Install.cmd"
Invoke-Command -Session $remotesess -ScriptBlock {$remotedir}我正在尝试在远程计算机上运行Install.cmd文件。我意识到我不能通过Enter-PSSession传递命令,但我正在努力解决这个问题。
发布于 2018-05-25 09:37:11
Invoke-Command -ComputerName <computerName>.&的命令。Invoke-Command -ComputerName ...的脚本块是远程执行的,因此不能直接在其中使用局部变量;在PSv3+中,解决此问题的最简单方法是使用using作用域:$using:<localVarName> 记住所有这些要点,我们得到:
$remoteinst = "\Windows\Temp\MyFolder"
$remotecomp = ComputerName # Note: This syntax assumes that `ComputerName` is a *command*
$remotedir = "C:" + $remoteinst + "\Install.cmd"
Invoke-Command -ComputerName $remoteComp -ScriptBlock { & $using:remotedir }发布于 2018-05-25 07:59:12
将cmd /c添加到批处理文件路径的前面。
https://stackoverflow.com/questions/50519225
复制相似问题