简体   繁体   中英

Powershell get overall CPU usage

I have a script that outputs my overall cpu usage. But if I compare this to the Task Manager, I get a different number. Is my script just wrong or is there a better way to do it?

$cpu = Get-WmiObject win32_processor 
logwrite $cpu.LoadPercentage

Task Manager says 26% while the output file says 1%. My script says 0%, 1% or 2% most of of the time.

任务管理器说26%,而输出文件说1%

The reason being, CPU Usage fluctuates with each passing moment, and that is reflected in your task manager. If you see your task manager the CPU usage will be fluctuating every time.

$cpu.LoadPercentage from your script gives you the CPU usage at the time of creation of your output file. Hence, you see the anomalies. You should be looking for a more dynamic way of getting CPU usage or getting it in intervals.

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