Is it possible to print the current CPU usage for each core in the system?
This is what I have so far using powershell:
Get-WmiObject -Query "select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor"
Is it possible to print the current CPU usage for each core in the system?
This is what I have so far using powershell:
Get-WmiObject -Query "select Name, PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor"
In Powershell Core 6 the commands have changed.
The script would look like this in Powershell Core 6.
As an alternative, you can use
Get-Counter
command.For example:
From my testing it's about 4 times faster (atleast on my machine) than querying WMI.EDIT: After testing some more, repeated uses of the query are faster (got mean of
284 ms
) becauseGet-Counter
needs minimum of 1 second to get the samples.It can be be done using the following powershell command:
Also you could create a file called
get_cpu_usage.ps1
with the contents:Then run it using: