PowerShell: Getting inventory details

Problem Statement:

I have a lot of servers on my network and my manager comes and tell me, “Can you get me details like the total RAM, HDD, Manufacturer, Serial Number and ServerName of all these servers?? I need to report this to Infrastructure team! Please get this in 2 hours time!!” Sounds laborious..Isn’t it??

Here's the script:
 "IP`tHardDisk`tRAM`tSystemName`tManufacturer`tSerialNumber" out-file C:\Results.csv -append

Function HDDInfo {
$alldrives = get-wmiobject win32_logicaldisk -filter "DriveType=3" -computername $ip
$HDD = 0
foreach ($i in $alldrives) { $HDD = $HDD + ($i.size)/(1gb) }
$HDD }

Function RAMInfo {
$ram = get-wmiobject win32_ComputerSystem -computername $ip
$RAM = ($ram.TotalPhysicalMemory)/(1gb)
$RAM }

Function SystemName {
$bios = get-wmiobject win32_bios -computer $ip
$bios.name }

Function Manufacturer {
$bios = get-wmiobject win32_bios -computer $ip
$bios.manufacturer }

Function SerialNumber {
$bios = get-wmiobject win32_bios -computer $ip
$bios.SerialNumber }

$address = "10.2.2."
2..254 foreach-object { $ip = $address + $_
$ping = get-wmiobject win32_pingstatus -filter "Address = '$ip'" select-object statuscode
if($ping.statuscode -eq 0) {
$HDD = HDDInfo $ip
sleep 1
$RAM = RAMInfo $ip
sleep 1
$SystemName = SystemName $ip
$Manufacturer = Manufacturer $ip
$SerialNumber = SerialNumber $ip
"$ip`t$HDD`t$RAM`t$SystemName`t$Manufacturer`t$SerialNumber" out-file C:\Results.csv -append }
else { "$ip is Offline or Not Reachable.." out-file C:\Results.csv -append }

In this script, I assume all your systems on the network are

in the IP range of 10.2.2.x and

I am collecting the details of IPs: -

Run the script, wait for 4-5 minutes and get the results in Results.csv file. 🙂


3 thoughts on “PowerShell: Getting inventory details

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s