To get CPU usage by process in PowerShell, you can use the `Get-Process
` command along with the Sort-Object cmdlet to sort the processes by CPU usage.
In this article, we will discuss how to get CPU usage by process and get CPU usage for the specific process using the PowerShell command.
How to Get CPU Usage by Process
Use the Get-Process cmdlet in PowerShell to get CPU usage by process. Here, is the PowerShell command to get CPU usage by process.
Get-Process | Sort-Object -Property CPU -Descending
In the above PowerShell script, the Get-Process command gets a list of all processes on the computer and pipes them to the Sort-Object
cmdlet to sort by CPU usage in descending order.
The Get-Process
cmdlet gets all the processes.
The Sort-Object
cmdlet sorts a collection of objects by the Property specified as CPU
.
The -Descending
parameter specifies that the object should be sorted in descending order.
The output of the above PowerShell script to sort the CPU usage by process displays the ProcessName, CPU, ID, Handles, and Threads. CPU column will contain the percentage of CPU usage by process.
You can get the top 10 CPU-utilizing processes in Windows using the PowerShell command as given below.
Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 10 | Format-Table -AutoSize
The above PowerShell command gets all the processes on the system, sorts them by CPU usage in descending order, and uses the Select-Object cmdlet to display the top 10 CPU-utilizing processes on the Windows system.
How to Get CPU usage for the specific process
To get CPU usage for the specific process, run the following command.
Get-Process -Name chrome | Select-Object -Property CPU
In the above PowerShell script, the Get-Process command gets CPU usage for the process named “Chrome
“.
The output of the above script returns the name of the process and the percentage of CPU usage by the process.
PS C:\> Get-Process -Name chrome | Select-Object -Property CPU
CPU
---
3.109375
1
351.75
882.453125
10.421875
62.78125
3111.953125
Cool Tip: How to get CPU usage in percentage using PowerShell!
Conclusion
I hope the above article on how to get CPU usage by the process using the PowerShell command Get-Process
is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.