Created
March 30, 2023 13:01
-
-
Save alsolovyev/bbcb32b229ea16c0eb07ebb7d421a8de to your computer and use it in GitHub Desktop.
Get Memory and CPU Usage in Windows 10 via Batch (cmd)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
for /f "tokens=2 delims=:" %%a in ('systeminfo ^| find "Available Physical Memory"') do set "avail_mem=%%a" | |
if %errorlevel% neq 0 ( | |
echo Error: Failed to get available physical memory | |
) else ( | |
echo Available memory: %avail_mem% | |
) | |
for /f "tokens=2 delims=:" %%a in ('systeminfo ^| find "Total Physical Memory"') do set "total_mem=%%a" | |
if %errorlevel% neq 0 ( | |
echo Error: Failed to get total physical memory | |
) else ( | |
echo Total memory: %total_mem% | |
) | |
for /f "skip=1 tokens=1-4" %%a in ('wmic cpu get loadpercentage') do ( | |
set "cpu_usage=%%a" | |
goto :done | |
) | |
:done | |
if %errorlevel% neq 0 ( | |
echo Error: Failed to get CPU usage | |
) else ( | |
echo CPU usage: %cpu_usage%%% | |
) | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment