终止由调用命令启动的远程作业
终止由调用命令与后台进程启动的远程作业的简单方法是什么?
我踢远程 PS 脚本来运行旧版 exe 文件,并且需要一种方法来终止该进程。
我本来打算首先使用 stop-job,但正如我正在阅读的那样,它仅适用于本地进程。
然后我打算使用 Remove-job -force 命令,但如果我理解正确的话,它无法终止正在运行的进程,直到它完成(我的远程 ps 脚本将再次启动另一个进程来运行 exe 文件)。
我正在读我可以使用 wmi终止命令杀死一个进程,但我不知道如何获取远程进程的PID(我不能使用名称,因为我可以杀死其他用户的进程)
实现我的目标的最佳方法是什么?
我的脚本看起来像这样:
invoke-command -computername server1,server2,server3..etc -script-block {my.exe} -asjob
loop to wait for all processes to complete and report progress
check for CTRL-C press and kill all remote instances on {my.exe}
what is the easy way to kill remote job initiated by invoke-command with background processes?
I kick remote PS script to run legacy exe file and need a way to kill that process.
I was going to use stop-job first but as I am reading it works only for local processes.
Then I was going to use Remove-job -force command but if I understood right, it cannot kill running process until it completes (again my remote ps script will start another process to run exe file).
I am reading I can kill a process using wmi terminate command but I do not know how to get PID of remote process (I cannot use name because I can kill processes from other users)
what is the best way to achieve my goal?
my script looks like that:
invoke-command -computername server1,server2,server3..etc -script-block {my.exe} -asjob
loop to wait for all processes to complete and report progress
check for CTRL-C press and kill all remote instances on {my.exe}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,今天早上下班检查了一下,这在调用脚本中工作得很好:
我对 MSDN 文档感到困惑,它说:
ok checked this morning from work and this works fine from a calling script:
I was confused by MSDN doc which says:
看看这个答案,您可以将启动进程命令添加到脚本块中并返回pid或将其保存到文本文件以供稍后参考。
PowerShell - 获取被调用应用程序的进程 ID
Check out this answer, you can add the start process command to your script block and return the pid or save it to a text file to be reference later.
PowerShell - get process ID of called application