Using memory.exe freeware, you can use the following command to set the mem numeric environment variable to the physical memory in bytes:

for /f "Tokens=*" %%a in ('memory /s') do set /a mem=%%a
You can use memupsec.bat to return the physical memory in kilobytes.

Using PsInfo.exe freeware, I have scripted TPMem.bat to return the physical memory in megabytes.

The syntax for using TPMem.bat is:

TPMem RAM

Where RAM is a call directed numeric environment variable that will contain the physical memory in megabytes.

TPMem.bat contains:

                              @echo off                              if \{%1\}==\{\} @echo Syntax: TPMem RAM&goto :EOF                              setlocal ENABLEDELAYEDEXPANSION                              for /f "Tokens=*" %%a in ('psinfo^|Find "Physical memory:"') do (                               for /f "Tokens=3" %%x in ('@echo %%a') do (                                set /a mem=%%x                               )                              )                              endlocal&set /a %1=%mem%