Get Logical Disk Size and Percentage of Free Disk Space with PowerShell

2011-05-21 Initial Post

Tested with PS v2 on Windows 7 and Server 2008 R2

I've found a few commands for getting disk size and free space but I wanted percentage of free space also. I modified one of the commands that I found by adding additional commands to show the percentage of free space. Note that DriveType=3 means local disk.

Get-WMIObject Win32_LogicalDisk -Filter "DriveType=3" -Computer . | Select SystemName, DeviceID, VolumeName, @{Name="Total Size (GB)"; Expression={"{0:N1}" -F ($_.Size/1GB)}}, @{Name="Free Space (GB)"; Expression={"{0:N1}" -F ($_.Freespace/1GB)}}, @{Name="Free Space %"; Expression={"{0:N1}" -F (($_.Freespace/$_.Size)*100)}} | FT -AutoSize

The output is below, but it doesn't line up properly in Outlook when I use the output string in an e-mail. I haven't had a chance to play around with the formatting.

SystemName     DeviceID VolumeName  Total Size (GB) Free Space (GB) Free Space %
----------     -------- ---------- --------------- --------------- ------------
Server001          C:        C-System    116.5             79.8              68.5
Server001          X:        X-Util      116.4             102.8             88.3

2 Responses to “Get Logical Disk Size and Percentage of Free Disk Space with PowerShell”

  1. matt Says:

    Hello,
    Do you know of a way to do a similar query that works around quotas? A number of servers that I am trying to query have quotas set on the volume of interest which affects the results.
    Many thanks.
    Matt

  2. SysAdmin-E Says:

    Hi Matt: Thanks for checking my site. I'm sorry but I've been very busy at work and haven't had time to look into this.

Leave a Reply

*