Thursday, October 31, 2013

Powershell Script to get RAM information

Powershell makes it easy to get information from remote servers.

Below is the query to "calculate RAM using powershell" of all the remote servers you are connected with-

Step1- Create the list of all the servers in a notepad with name "serverlist.txt". I have saved this file on location "D:\Powershell" you can change it with your own location.

Step2- Execute below script-

$servers = Get-Content "D:\PSScripts\bstServerlist.txt"

$SystemInfo = "D:\PSScripts\bstSystemInfo.txt"
$ErrorInfo = "D:\PSScripts\bstErrorInfo.txt"

FOREACH($server in $servers)
$System = gwmi -computer $server -class win32_computersystem -ErrorVariable MyError -ErrorAction Silentlycontinue

$Ram = [math]::round($System.Totalphysicalmemory/(1024*1024*1024),2)
write-output "$server - $Ram " | out-file -filepath $SystemInfo -append

You can also save the script in a notepad and save it with extension ".ps1". When you will execute the file RAM information for all the servers in the server list will store in the RAMInformation file.

No comments:

Post a Comment