You can get CPU usage on Windows XP and Windows 7 using both Command Prompt and PowerShell. Here are the most common methods:
1. Using Command Prompt (CMD)
A. Using typeperf
typeperf is available on both XP and 7.
cmd
typeperf "\Processor(_Total)\% Processor Time" -sc 1
- This command will output the current CPU usage as a percentage.
-sc 1 means it will sample once and then stop.
Example Output:
code
"(PDH-CSV 4.0)","\\COMPUTERNAME\processor(_total)\% processor time"
"06/21/2025 13:00:00.123","12.345678"
B. Using wmic
wmic is available on both XP and 7.
cmd
wmic cpu get loadpercentage
Example Output:
code
LoadPercentage
15
2. Using PowerShell
A. Using Get-WmiObject
powershell
Get-WmiObject win32_processor | Select-Object -ExpandProperty LoadPercentage
- This will return the CPU load percentage.
B. Using Get-Counter (Windows 7 and later)
powershell
(Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples[0].CookedValue
- This gives a more precise value, but
Get-Counter is not available on XP by default.
Summary Table
| Method | Windows XP | Windows 7 | Command/Script |
|---|
typeperf | Yes | Yes | typeperf "\Processor(_Total)\% Processor Time" -sc 1 |
wmic | Yes | Yes | wmic cpu get loadpercentage |
| PowerShell WMI | Yes | Yes | `Get-WmiObject win32_processor |
| PowerShell Get-Counter | No | Yes | (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples[0].CookedValue |
Note:
- On Windows XP, PowerShell is not installed by default, but can be added (v1.0 or v2.0).
Get-Counter is not available in PowerShell 1.0 (XP), but is in PowerShell 2.0+ (Windows 7).
Let me know if you need a script to log or monitor CPU usage over time!