How to Get Disk Size and Free Space Using PowerShell

Introduction

Sometimes IT Admin or Software Engineers have a task to get information about disk space. Rather than navigating Windows Explorer to get information, they can automate using PowerShell which is much quicker.

In this article, we’ll walk through how to get information about disk size and free space using PowerShell.

Solution

Using Get-PSDrive Cmdlet

Get-PSDrive cmdlet can be used to get drive information.


Get-PSDrive

To get drive information on specific drive, we can specify the drive name:


Get-PSDrive -Name C

The information will looke like below image:

using get-psdrive to get disk size and free space

Using Get-Volume Cmdlet

Get-Volume cmdlet can also be used to get disk size and free space.


Get-Volume

To get drive information on specific drive, we can specify the drive name:


Get-Volume -DriveLetter C

The information will looke like below image:

using get-volume to get disk size and free space

Using Get-WmiObject Cmdlet

You can also use Get-WmiObject cmdlet to get disk size and free space.


Get-WmiObject -ClassName Win32_LogicalDisk | ForEach-Object {
    [PSCustomObject]@{
        DeviceID  = $_.DeviceID
        Size      = [Math]::Round($_.Size / 1GB, 2)
        FreeSpace = [Math]::Round($_.FreeSpace / 1GB, 2)
    }
}

The result will look like below image: using get-wmiobject to get disk size and free space

Using Get-CimInstance Cmdlet

You can also use Get-CimInstance cmdlet to get disk size and free space.


Get-CimInstance -ClassName Win32_LogicalDisk | ForEach-Object {
    [PSCustomObject]@{
        DeviceID  = $_.DeviceID
        Size      = [Math]::Round($_.Size / 1GB, 2)
        FreeSpace = [Math]::Round($_.FreeSpace / 1GB, 2)
    }
}

The result will look like below image: using get-ciminstance to get disk size and free space

Conclusion

There are 4 cmdlet that can be used to get disk size and free space using PowerShell: Get-PSDrive, Get-Volume, Get-WmiObject, and Get-CimInstance.