【发布时间】:2016-02-26 16:03:38
【问题描述】:
我正在尝试使用 powershell 运行位于计算机 A 上的 bat 脚本并在计算机 B 上执行它
计算机 A 是调用 Invoke Command 函数的计算机
我正在尝试通过
Invoke-Command -ComputerName ComputerB -ScriptBlock{& "\\ComputerA\filepath\batch.bat"} -Credential $Cred
当我运行它时,我收到了错误
The term '\\ComputerA\filepath\batch.bat' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我也尝试通过在计算机 B 上调用 cmd 来运行它,并将这个 bat 脚本作为参数传递,我没有收到任何错误,但我可以告诉脚本没有运行 我使用的命令是
Invoke-Command -ComputerName ComputerB -ScriptBlock{& "C:\Windows\System32\cmd.exe"} -ArgumentList "\\ComputerA\filepath\batch.bat" -Credential $Cred
当我进入计算机 B 并通过 cmd 手动调用脚本时,它可以工作
我确认 Invoke-Command 有效,因为我能够运行计算机 B 本地的程序
我试图不必在计算机 B 上放置任何文件,例如 psexec 或 bat 脚本本身,这就是我尝试这种方式的原因
谢谢
【问题讨论】:
-
是的,我可以在两台计算机上本地运行它我可以进入 ComputerB 并通过 cmd 我可以输入 \\ComputerA\filepath\batch.bat 并让它运行良好我也可以通过 Windows 运行它探险家
标签: powershell cmd remote-debugging remoting powershell-remoting