Powershell – Check Free Memory script

 

Here’s a quick script I did using Powershell to check your free memory and report back the amount in MB and GB.

 

$freemem = Get-WmiObject -Class Win32_OperatingSystem

# Display free memory on PC/Server
"---------FREE MEMORY CHECK----------"
""
"System Name     : {0}" -f $freemem.csname
"Free Memory (MB): {0}" -f ([math]::round($freemem.FreePhysicalMemory / 1024, 2))
"Free Memory (GB): {0}" -f ([math]::round(($freemem.FreePhysicalMemory / 1024 / 1024), 2))
""
"------------------------------------"

Download the script here

 

The figure is determined and held in the $freemem variable. After that we simply output two lines to show the amount in MB and GB. We use a simple function to divide the figure by 1024 and round it off, displaying the result with two decimal places. The figure needs to be divided by 1024 as the variable holds the amount in Kilobytes (KB), therefore to determine Megabytes (MB), we divide by 1024. The second figure for GB requires one more division.