如何使用 PowerShell 來獲得特定程序資訊?


  • 若要使用 Get-Process cmdlet 查詢特定程序,您需要使用 –Name 引數。您可以使用一個或多個程序名稱。

命令

Get-Process -Name AcroRd32, audiodg

輸出

Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
506 27 9888 19216 2.22 6320 1 AcroRd32
632 51 112196 17648 42.95 8052 1 AcroRd32
209 13 10344 17100 13.98 22748 0 audiodg

您還可以使用 Where-Object (別名:Where) 命令實現同樣的功能。

Get-Process | Where{$_.Name -eq "AcroRd32"}

但要獲取多個程序,您需要使用 –OR 比較運算子。

Get-Process | Where{($_.Name -eq "AcroRd32") -or ($_.Name -eq "AudioDg")}

結果將與上面顯示的一樣。

  • 若要使用 WMI 物件獲取特定程序資訊,您可以使用 –Filter 引數或管道 Where-Object 命令。

    使用 Where-Object 命令。

Get-WmiObject Win32_Process | Where{($_.Name -eq "AcroRd32.exe") -or ($_. Name -eq "AudioDg.exe")}

使用 –Filter 引數。

Get-WmiObject Win32_Process -Filter {Name = 'AcroRD32.exe'}

若要獲取多個程序,您需要使用 AND 比較運算子。

Get-WmiObject Win32_Process -Filter {Name = 'AcroRD32.exe' or Name = 'AudioDg.exe'}

更新時間: 2020 年 1 月 22 日

2K+ 瀏覽量

啟動你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.