启动psexec后获取进程ID [英] Get Process ID after starting psexec
本文介绍了启动psexec后获取进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本可以使用 psexec 在远程计算机上调用记事本.有没有办法在启动后获取进程 ID?
I have a script that calls notepad on a remote computer with psexec. Is there a way I can get the Process ID after it is started?
这是我所拥有的:
$PCname = "MyPC"
$SessionID = "2"
$Program = "Notepad.exe"
$FilePath = "C:\temp\"
$FileName = "Test.txt"
set-alias psexec "C:\PsExec\psexec.exe"
&psexec -s -d -i $SessionID \\$PCname $Program $FilePath\$FileName
运行后,我在显示进程 ID 的输出窗口中得到这个:
After running I get this in the output window that shows the Process ID:
Connecting to MyPC...Starting PSEXESVC service on MyPC...Connecting
with PsExec service on MyPC...Starting Notepad.exe on MyPC...
Notepad.exe started on MyPC with process ID 8352.
如何获取进程 ID?
推荐答案
您可以使用 Select-String
cmdlet 通过 regex 获取进程 ID:>
You can use the Select-String
cmdlet to grab the process ID using a regex:
&psexec -s -d -i $SessionID \\$PCname $Program $FilePath\$FileName |
Select-String 'process ID (\d+)' |
ForEach-Object {$_.Matches.Groups[1].Value}
这篇关于启动psexec后获取进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文