如何从Windows命令提示符获得总CPU使用率?:
预期产出:
27%
答案 0 :(得分:80)
C:\> wmic cpu get loadpercentage
LoadPercentage
0
或者
C:\> @for /f "skip=1" %p in ('wmic cpu get loadpercentage') do @echo %p%
4%
答案 1 :(得分:11)
以下命令提示符在Windows 7 Ultimate上正常运行:
C:\Windows\system32>typeperf "\Processor(_Total)\% Processor Time"
"(PDH-CSV 4.0)","\\vm\Processor(_Total)\% Processor Time"
"02/01/2012 14:10:59.361","0.648721"
"02/01/2012 14:11:00.362","2.986384"
"02/01/2012 14:11:01.364","0.000000"
"02/01/2012 14:11:02.366","0.000000"
"02/01/2012 14:11:03.367","1.038332"
The command completed successfully.
C:\Windows\system32>
或快照:
C:\Windows\system32>wmic cpu get loadpercentage
LoadPercentage
8
答案 2 :(得分:8)
typeperf "\processor(_total)\% processor time"
适用于Win7,您只需要从最后一个引用的字符串中提取百分比值。
答案 3 :(得分:1)
typeperf
在某些计算机上随机无效(Error: No valid counters.
)或帐户权限不足时,会向我提出问题。否则,这是一种从输出中仅提取值的方法。它仍然需要四舍五入:
@for /f "delims=, tokens=2" %p in ('typeperf "\Processor(_Total)\% Processor Time" -sc 3 ^| find ":"') do @echo %~p%
Powershell有两个cmdlet可以获得所有CPU的利用率百分比:Get-Counter
(首选)或Get-WmiObject
:
Powershell "Get-Counter '\Processor(*)\% Processor Time' | Select -Expand Countersamples | Select InstanceName, CookedValue"
或者,
Powershell "Get-WmiObject Win32_PerfFormattedData_PerfOS_Processor | Select Name, PercentProcessorTime"
使用格式化输出获得整体CPU负载,与问题完全相同:
Powershell "[string][int](Get-Counter '\Processor(*)\% Processor Time').Countersamples[0].CookedValue + '%'"
或者,
Powershell "gwmi Win32_PerfFormattedData_PerfOS_Processor | Select -First 1 | %{'{0}%' -f $_.PercentProcessorTime}"
答案 4 :(得分:0)
对于任何偶然浏览此页面的人,这里的解决方案都不适合我。我发现这是这样做的方法(在批处理文件中):
@for /f "skip=1" %%p in ('wmic cpu get loadpercentage /VALUE') do (
for /F "tokens=2 delims==" %%J in ("%%p") do echo %%J
)