Checking CPU utilization
One of the best ways to monitor CPU utilization with PowerShell is by querying performance counters. We can also get this information using WMI. In this recipe, you'll learn a few techniques that can be used to monitor CPU utilization using the
Get-Counter
and
Get-WmiObject
cmdlets.
How to do it...
To get an idea of the current CPU utilization for a server, we can gather data for the
Processor(_Total)\% ProcessorTime
performance counter:Get-Counter "\Processor(_Total)\% Processor Time" -Continuous
This would continuously output the total utilization across each CPU, as shown:
In addition, we can use the
Win32_Processor
class and select theLoadPercentage
property to determine the utilization for each CPU:Get-WmiObject Win32_Processor | select LoadPercentage
Note
Both
Get-Counter
andGet-WmiObject
support the-ComputerName
parameter and can be run against remote machines.
How it works...
The Processor(_Total)\% ProcessorTime
performance counter measures the total utilization...