Friday, August 8, 2008

Getting Available Memory On Remote Servers

I am often asked to give total and available memory across our enterprise to our Disaster Recovery guys. Here is a simple script that achieves that goal:

$Servers = Get-Content 'c:\ProductionScripts\Servers.txt'
Write
-Host "Server,Total,Free"
foreach ( $server in $Servers )
{
$drives
= Get-WmiObject `
-Class Win32_LogicalDisk `
-ComputerName $server `
-Filter "DriveType=3" `
-ErrorAction SilentlyContinue
$size
= 0
$available
= 0
foreach($drive in $drives)
{
[
double]$size += $drive.size
[
double]$available += $drive.freespace
}

$str
= "{0},{1},{2}" -f $server,[MATH]::Round($size/1MB),[MATH]::Round($available/1MB)
Write
-Host $str
}




2 comments:

AlbertWT said...

Hi,

is that a drive space or a RAM size ? I think you got a typo in the title section :-)

culter said...

Exactly! It's disk size and free disk space, not available memory. Big Fail!