Monitoring drive space

One of the things that we spend a lot of time on is trying to keep track of what servers have enough free space.  We have a lot of different tools to check drive space, and we even use some of them from time to time.  We have a pretty complicated system created by Rickey that creates a nice webpage, with highlighting for problem areas (percentage change from day to day, current percent free, etc.)  It even puts the info into a database for historical reporting.

We don’t store or report on VMs currently, mainly because we were trying to keep track of total REAL disk used.  VMs often don’t use as much as they think they do, so that would skew the results, as well as the fact that we are reporting on the hosts. 

All of that is the reason that Patrick asked me to come up with some other tool to use for the VMs so I happened to find a few pieces of PowerShell script that I managed to put together to do a pretty good job of providing some of the info we wanted, and I thought I would share that with the 2 people who read my blog.  🙂


$servers = Get-Content servers.txt

#Open Excel and create a new workbook and worksheet
$ExcelSheet=New-Object -comobject Excel.application   

#Header row
$WorkSheet.cells.item(1,1)=”Computer Name”               
$WorkSheet.cells.item(1,2)=”Disk Device ID”              
$WorkSheet.cells.item(1,3)=”Volume Name”                 
$WorkSheet.cells.item(1,4)=”Size (GB)”        
$WorkSheet.cells.item(1,5)=”Free Space (GB)”
$WorkSheet.cells.item(1,6)=”Space Used (GB)”
$WorkSheet.cells.item(1,7)=”Percent Used”


ForEach ($ComputerName in $servers)
    echo "Server Name : ", $ComputerName
    $Disks = gwmi –computername $ComputerName win32_logicaldisk -filter "drivetype=3"

    foreach ($Disk in $Disks)
        $Size = "{0:0.0}" -f ($Disk.Size/1GB)
        $FreeSpace = "{0:0.0}" -f ($Disk.FreeSpace/1GB)
        $Used = ([int64]$Disk.size – [int64]$Disk.freespace)
        $SpaceUsed = "{0:0.0}" -f ($Used/1GB)
        $Percent = ($Used * 100.0)/$Disk.Size
        $Percent = "{0:N0}" -f $Percent

#Show the results

Leave a Reply

%d bloggers like this: