启动后获取进程ID psexec
问题描述:
我有一个脚本,用psexec在远程计算机上调用记事本。有没有一种方法可以在启动后获得进程ID?启动后获取进程ID psexec
以下是我有:
$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的输出窗口:
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的使用正则表达式向抢进程ID:
&psexec -s -d -i $SessionID \\$PCname $Program $FilePath\$FileName |
Select-String 'process ID (\d+)' |
ForEach-Object {$_.Matches.Groups[1].Value}
答
$a = (gps -ComputerName PcName| where{ $_.ProcessName -eq "Notepad.exe"} | select Id)
$a.Id
包含通缉编号
+0
如果机器上运行的唯一记事本是我开始使用的记事本,那么这很有效。 – Eric
我有点新手的。我如何从中获得我的进程ID? – Eric
它已经返回进程ID ;-) –
???我搞不清楚了。看不到它在哪里返回进程ID – Eric