Wednesday, December 19, 2012

PowerShell Script to retrieve disk size (GB) & free disk space (GB) from multiple servers



Monitoring disk usage becomes increasingly important with the huge growth of data. Current monitoring tools are often too extensive and sometimes even very difficult to use.
Using PowerShell it is easily to retrieve a nice overview of disk size (GB) and free disk space (GB) from multiple servers. With such a script it is possible to analyze trends in disk usage over a specified period.
Step 1
Create a directory (for example “P:\Servers”) with a file called “Servers.txt” in it.
List all servers within the text file where you want to retrieve the disk usage from.



Step 2
Start PowerShell and run the PowerShell command as specified below.


Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content .\Servers.txt) | Select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} | Out-GridView
Step 3
You will get an overview of disk usage from all listed servers. From this grid you can cut and paste all the information into a spreadsheet to make alternate calculations and graphs.



No comments:

Post a Comment