Cmd 如何使用批处理文件查找CPU、RAM和内存使用率的百分比

Cmd 如何使用批处理文件查找CPU、RAM和内存使用率的百分比,cmd,Cmd,我想显示CPU使用率百分比和可用CPU百分比, RAM和运行程序也一样,带有日期和时间戳 @echo off Powershell -command "&{Get-WmiObject -Query 'Select * from Win32_PerfFormattedData_PerfProc_Process '| Select Name, @{Name='CPU(p)';Expression={$_.PercentProcessorTime}} | where {$_.'CPU(p)'

我想显示CPU使用率百分比和可用CPU百分比, RAM和运行程序也一样,带有日期和时间戳

@echo off 
Powershell -command "&{Get-WmiObject -Query 'Select * from Win32_PerfFormattedData_PerfProc_Process '| Select Name, @{Name='CPU(p)';Expression={$_.PercentProcessorTime}} | where {$_.'CPU(p)' -gt 0 } |Sort 'CPU(p)' -descending | Format-Table -AutoSize;}" 
Powershell -command "&{Get-Process | Select Name, @{Name='CPU(s)';Expression={$_.CPU}} | sort 'CPU(s)' -Descending | Select -First 5| Format-Table -AutoSize;}"
 Powershell -noexit -command "&{Get-WmiObject -Query 'Select * from Win32_OperatingSystem' | Select FreePhysicalMemory | Format-Table -AutoSize;}
我尝试了上面的代码,但我希望输出像CPU%利用率%Free、RAM%利用率%Free、程序%CPU%RAM这样的数据。试试这个:

@echo off

set totalMem=
set availableMem=
set usedMem=
for /f "tokens=4" %%a in ('systeminfo ^| findstr Physical') do if defined totalMem (set availableMem=%%a) else (set totalMem=%%a)

set totalMem=%totalMem:,=%

set availableMem=%availableMem:,=%

set /a usedMem=totalMem-availableMem

Echo Total Memory: %totalMem%
Echo Used Memory: %usedMem%



setlocal enabledelayedexpansion

set Times=0

for /f "skip=1" %%p in ('wmic cpu get loadpercentage') do (

set Cpusage!Times!=%%p

set /A Times=!Times! + 1

)

echo Percentage = %Cpusage0%

来源:

您尝试了什么以及失败的地方?@echo off Powershell-command“&{Get WmiObject-Query'Select*from Win32_performatteddata_PerfProc_Process'| Select Name,@{Name='CPU(p);(Expression={$.PercentProcessorTime}}}where{$'CPU(p)'-gt 0}排序'CPU(p)'-降序|格式表-自动调整大小;}“Powershell-command”&{Get Process | Select Name,@{Name='CPU(s)};Expression='CPU(s)}排序'CPU(s)'-降序|选择-First 5 |格式表-AutoSize;}“Powershell-noexit-命令”&{Get WMIOObject-查询'Select*from Win32_操作系统'|选择FreePhysicalMemory |格式表-AutoSize;}”将带有格式的代码添加到问题中。但我需要CPU%利用率%Free、RAM%利用率%Free、程序%CPU%rama等输出将这些详细信息添加到问题中以更快获得帮助。感谢您的回答,我还需要RAM百分比和正在运行的程序利用率