Windows11のbatファイルで物理メモリ容量を取得する

@echo off
setlocal enabledelayedexpansion
    set memoryinfo=
    for /f "usebackq tokens=*" %%i in (`wmic computersystem get TotalPhysicalMemory`) do (
        set memoryinfo=!memoryinfo!^%%i
    )
    set memory=
    for %%p in (%memoryinfo%) do (
        set test=number%%p
        set test=!test:0=!
        set test=!test:1=!
        set test=!test:2=!
        set test=!test:3=!
        set test=!test:4=!
        set test=!test:5=!
        set test=!test:6=!
        set test=!test:7=!
        set test=!test:8=!
        set test=!test:9=!
        if "!test!" == "number" (
            set memory=%%p
        )
    )
    set memory=%memory:~0,-3%
    echo %memory%KB
    set /a memory=%memory%/1000
    echo %memory%MB
    set /a memory=%memory%/1000
    echo %memory%GB
endlocal
pause