如何使用 PowerShell 獲取 Windows 效能計數器?


要使用 PowerShell 獲取 Windows 效能計數器,我們可以使用 **Get-Counter** cmdlet。

有各種效能計數器可用於衡量 Windows 作業系統的效能。**Get-Counter** cmdlet 用於檢索本地或遠端系統上特定計數器名稱的效能。

當您只執行 Get-Counter 命令時,它會顯示本地系統上的主要基本計數器,例如網絡卡、處理器、磁碟等,如下所示。

示例

PS C:\> Get-Counter
Timestamp                 CounterSamples
---------                 --------------
4/7/2021 7:41:42 PM       \labmachine2k16
etwork interface(intel[r] 82574l gigabit network connection)\bytes total/sec :                           0                           \labmachine2k16
etwork interface(isatap.{5008ca11-6974-4ec6-b2d7-eef6f9632c45})\bytes total/sec :                           0                           \labmachine2k16\processor(_total)\% processor time :                           65.3778486182899                           \labmachine2k16\memory\% committed bytes in use :                           36.8481297364571                           \labmachine2k16\memory\cache faults/sec :                           1168.99908419505                           \labmachine2k16\physicaldisk(_total)\% disk time :                           16.2392354345686                           \labmachine2k16\physicaldisk(_total)\current disk queue length :                           2

要獲取遠端系統上的計數器,請使用 -**ComputerName** 引數。

示例

Get-Counter -ComputerName TestMachine

要獲取各種可用的計數器列表,請使用 **-ListSet** 引數。

示例

Get-Counter -ListSet *

輸出

您可以看到 **counterSetName** 及其在 **Counter** 屬性中的各種計數器。**machinename** 屬性顯示本地或遠端計算機。點 (.) 表示本地計算機名稱。

要查詢與 **Processor** 相關的特定計數器,請使用以下命令。

示例

Get-Counter -ListSet * | where{$_.CounterSetName -like "*Processor*"} | Select CounterSetName, Counter

輸出

同樣,要獲取與磁碟相關的計數器,請使用以下命令:

示例

Get-Counter -ListSet * | where{$_.CounterSetName -like "*disk*"} | Select CounterSetName, Counter

更新於: 2021年4月12日

783 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告