How to check available memory (RAM) via batch script?

batch-file, windows-7, windows-xp

Solution

This site has a sample VBScript that retrieves the total amount of memory:

http://www.computerperformance.co.uk/vbscript/wmi_memory.htm

It can be adapted to report the available amount of memory:

' Memory.vbs
' Sample VBScript to discover how much RAM in computer
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.3 - August 2010
' -------------------------------------------------------' 

Option Explicit
Dim objWMIService, perfData, entry 
Dim strLogonUser, strComputer 

strComputer = "." 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
Set perfData = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_PerfOS_Memory") 

For Each entry in perfData 
Wscript.Echo "Available memory bytes: " & entry.AvailableBytes
Next

WScript.Quit

You can run it by saving it to a file with extension `.vbs` (e.g. `memory.vbs`) and running it with cscript.exe, e.g.:

cscript.exe //nologo memory.vbs

...to get output like:

Available memory bytes: 4481511424

Problem

I would like to know that how we can check the available memory in batch script? Is there any method already available? If it is not possible in batch script then is there any other way by which we can get the memory available? OS: Windows XP / Windows 7

Original source