Retrieving Disk Information and Freespace Using PowerShell 2

It is always nice to be able to retrieve disk information for the systems. Alot of scripts are used to gather the information so Administrators can keep ahead of the demand for space. With PowerShell 2 it is simple to retrieve the information in a single line using the win32_volume WMI class call. Now in this example I am only retrieving four items and rounding the values to two decimal places. There are many more retrievable variables referenced here.

So here is the command.

gwmi win32_volume -Filter ‘drivetype = 3’ | select driveletter, label, @{Name=”Capacity(GB)”;expression={[math]::round(($_.Capacity/ 1073741824),2)}}, @{Name=”FreeSpace(GB)”;expression={[math]::round(($_.FreeSpace / 1073741824),2)}}

So what am I trying to do? Well, in  this example we are looking for Local disks and outputting the driveletter, label, capacity and the freespace. When retrieving the capacity and freespace we are rounding it in GB to two decimal places. Here are the results from a system with fiber attached storage and drives mounted to folders.


Now that we see what a single line can do we can apply this as a function and use in combination with other scripts.


function Get-MountPoint ()
   $TotalGB = @{Name=”Capacity(GB)”;expression={[math]::round(($_.Capacity/ 1073741824),2)}}
   $FreeGB = @{Name=”FreeSpace(GB)”;expression={[math]::round(($_.FreeSpace / 1073741824),2)}}  
   $volumes = gwmi win32_volume -Filter 'drivetype = 3' | Select driveletter, Label, $TotalGB, $FreeGB

Run  the function by calling Get-MountPoint () and thats all you need.




One Response to “Retrieving Disk Information and Freespace Using PowerShell 2”

  1. long_ashes says:

    I made a drive monitor script completely based on win32_volume once, but it never saw the light of day in production. Gotta love wmi, one of the only things Microsoft provides that’s useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.