我想知道如何获取任务管理器中显示的进程的“命令行”属性。我的意思是,如果我运行以下命令
Get-Process -Name "Firefox" | ? {$_.TotalProcessorTime -ne $Null} | Select-Object -Property Name, Id, Path
我明白了:
Name Id Path
---- -- ----
firefox 728 C:\Program Files\Mozilla Firefox\firefox.exe
firefox 2260 C:\Program Files\Mozilla Firefox\firefox.exe
firefox 2612 C:\Program Files\Mozilla Firefox\firefox.exe
firefox 3992 C:\Program Files\Mozilla Firefox\firefox.exe
但我不需要“Path”属性,而是需要命令行,我的意思是例如:
Name Id **Command Line**
---- -- ----
firefox 728 **"C:\Program Files\Mozilla Firefox\firefox.exe" -contentproc --chanel="1306.3.14958**
firefox 2260 **"C:\Program Files\Mozilla Firefox\firefox.exe" -contentproc --chanel="1306.4.9583**
firefox 2612 **"C:\Program Files\Mozilla Firefox\firefox.exe" -contentproc --chanel="1306.5.1392**
firefox 3992 **"C:\Program Files\Mozilla Firefox\firefox.exe" -contentproc --chanel="1306.6.21397**
稍后对字符串的一部分进行过滤(执行 grep),找到命令行列(例如:1306.5.1392)我知道我可以使用 findstr -i "1306.5.1392",但不确定是否可以这是最聪明的方法
非常感谢您的帮助!
亲切的问候
最佳答案
查询the Win32_Process
WMI class的实例获取命令行:
Get-CimInstance -ClassName Win32_Process -Filter "Name = 'firefox.exe'" |Where-Object {
(Get-Process -Id $_.ProcessId).TotalProcessorTime -ne $null
} |Select Name,ProcessId,CommandLine
如果您想在输出中包含 TotalProcessorTime
值,请在过滤之前使用 Select-Object
:
Get-CimInstance -ClassName Win32_Process -Filter "Name = 'firefox.exe'" |Select-Object Name,ProcessId,CommandLine,@{Name='TotalProcessorTime';Expression={(Get-Process -Id $_.ProcessId).TotalProcessorTime}} |Where-Object { $_.TotalProcessorTime -eq $null }
关于powershell - 如何在powershell中获取进程的 "Comand Line"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73988459/