简体   繁体   中英

Get Process for CPU usage in powershell

This particular code in Powershell is to generate CPU usage (in percentage) same as the task manager. But, the problem with this one is that it runs for once and for all not continuously.

Get-Process | Select-Object -Property Name, CPU, $CPUPercent, Description |Sort-Object -Property CPUPercent -Descending

How do I take the results continuously in mentioned time interval?

Where is the mentioned time interval? You can take the results continuously using a do while loop:

do
{
    Get-Process | Select-Object -Property Name, CPU, $CPUPercent, Description |Sort-Object -Property CPUPercent -Descending
    Sleep 1
}
while ($true)

Note : Im using the Sleep cmdlet to reduce the outputs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM