In todayโs technology-driven world, managing disk space efficiently is crucial to ensuring the smooth functioning of your computer systems or servers. As files and applications continue to accumulate, itโs essential to monitor and analyze disk space regularly.
Thankfully, PowerShell, a powerful scripting language and automation framework from Microsoft, provides several convenient methods to check disk space effortlessly.
In this blog post, we will explore different PowerShell commands and scripts to get free disk space on your Windows machines.
PowerShell Check Disk Space: Get-Volume
The Get-Volume cmdlet in PowerShell lets you retrieve information about your computerโs volumes (logical drives).
Check Free Disk Space on All Volumes
To check the free disk space of all available volumes, open a PowerShell window and execute the following command:
Get-Volume
This command will display a detailed list of all volumes, their capacity, free space, and other essential information. The output will help you identify which volumes run low on disk space.

Check Free Disk Space on a Specific Drive Letter
By specifying the drive letter, you can limit the result to a specific volume. For example, the below command returns the free disk space information on drive D.
Get-Volume -DriveLetter D

Check Free Disk Space Based on Drive Type
In most cases, monitoring the disk space only applies to fixed disks. Using the Where-Object cmdlet, you can filter the output to show only the fixed disks.
This command gets all volumes information and filters the DriveType parameter matching the word โFixedโ.
Get-Volume | Where-Object {$_.DriveType -eq 'Fixed'} 
Check Free Disk Space on Volumes with Assigned Drive Letters
Another way to filter results is to show only fixed drives with assigned drive letters. Take the sample command in the previous example. But this time, add another condition to show only volumes with non-empty drive letters.
Get-Volume | Where-Object {$_.DriveType -eq 'Fixed' -and $_.DriveLetter} 
PowerShell Storage Module: Get-Disk, Get-Partition, and Get-PhysicalDisk
Modern Windows versions include the Storage PowerShell module, which provides detailed info about physical disks, partitions, and storage devices. While Get-Volume is useful for checking free space, storage cmdlets help you to troubleshoot capacity, partition layout, and hardware-related storage issues.
Here are some examples of usage. The following command displays physical disk info including disk number, size, partition style, and operational status:
Get-Disk |
Select-Object Number,FriendlyName,Size,PartitionStyle,OperationalStatus
The following command displays partition info, including drive letters and partition sizes:
Get-Partition |
Select-Object DiskNumber,PartitionNumber,DriveLetter,Size

View Physical Storage Devices
The Get-PhysicalDisk cmdlet provides hardware-level storage information such as health status, media type, and operational state. This command is especially useful in Storage Spaces and modern storage environments:
Get-PhysicalDisk |
Select-Object FriendlyName,MediaType,HealthStatus,OperationalStatus,Size
Note. Get-Disk, Get-Partition, and Get-PhysicalDisk focus on storage infrastructure rather than available free space. To check free capacity on volumes, you should use Get-Volume or Win32_LogicalDisk.
PowerShell Check Disk Space: Get-PSDrive
Another useful cmdlet for checking disk space is Get-PSDrive. While Get-Volume is specific to volumes, Get-PSDrive provides information about all the available drives, including file system drives and registry drives.
Check Free Disk Space on All Drives
Running this command will give you a list of drives and their properties, including available free space.
Get-PSDrive

Check Free Disk Space on FileSystem Drives Only
But as you can see, the command returned all PowerShell drives. But weโre only interested in the FileSystem provider. To get only the FileSystem drives, letโs use the -PSProvider parameter.
Get-PSDrive -PSProvider FileSystem

Check Free Disk Space on Specific Drives
You can also get free disk space for specific drives only by specifying the drive letter using the -Name parameter.
Get-PSDrive -Name C

PowerShell Check Disk Space: Win32_LogicalDisk Class
WMI (Windows Management Instrumentation) is a powerful feature in Windows that allows you to access system information, local or remote. In it, there are classes that expose this system information that you can query.
One such class is the Win32_LogicalDisk class, which includes the disk name, size, and free space. You can query this class using either Get-WmiObject or Get-CimInstance.
Both cmdlets can retrieve similar info from the Win32_LogicalDisk class. However, Get-WmiObject is only available in Windows PowerShell 5.1 and earlier. It is not available in PowerShell 7+ because PowerShell Core does not support the legacy WMI cmdlets. For modern scripts, automation, and cross-platform compatibility, you should use Get-CimInstance instead. You should use Get-WmiObject only when maintaining older Windows PowerShell scripts.
Check Free Disk Space on a Local or Remote Computer
For example, the following PowerShell check disk space commands query the disk information from the remote computer called DC1.
Get-CimInstance -Class Win32_LogicalDisk -ComputerName DC1 | ` Format-Table SystemName, DeviceID, DriveType, VolumeName, Size, FreeSpace -AutoSize
Note. If querying the local computer, remove the -ComputerName parameter entirely or replace the computer name with a dot (i.e., -ComputerName .)

Keep in mind that the FreeSpace and Size values are shown in bytes.
Check Free Disk Space on Multiple Computers
You can also query multiple machines at once by specifying their hostnames in the -ComputerName parameter. For example, to query DC1 and DC2, the command is:
Get-CimInstance -Class Win32_LogicalDisk -ComputerName DC1, DC2 | ` Format-Table SystemName, DeviceID, DriveType, VolumeName, Size, FreeSpace -AutoSize
Note. The Win32_LogicalDisk class does not return network-mapped drives on remote computers. To get mapped drives on remote machines, use the Win32_MappedLogicalDisk class instead.

Query Remote Computers with CIM Sessions
We recommend CIM sessions when you need to repeatedly query remote machines because they reuse the same management connection and reduce overhead:
$cim = New-CimSession -ComputerName DC1
Get-CimInstance `
-Class Win32_LogicalDisk `
-CimSession $cim
When finished, close the CIM session:
Remove-CimSession $cim
Check Free Disk Space with WMI Filter
While a machine can have different drive types, monitoring mostly makes sense only on local disks. When running the PowerShell check disk space query with Get-WMIObject or Get-CIMInstance, you can filter the drive type to return.
Below is the list of available drive types:
- 0 = Unknown
- 1 = No Root Directory
- 2 = Removable Disk
- 3 = Local Disk
- 4 = Network Drive
- 5 = Compact Disc
- 6 = RAM Disk
We know that the fixed or local drive type number is 3. So we can add the -Filter “DriveType = 3โ filter.
Get-CimInstance -Class Win32_LogicalDisk -ComputerName DC2 -Filter "DriveType = 3" |
Format-Table SystemName, DeviceID, DriveType, VolumeName, Size, FreeSpace -AutoSize
In case you maintain legacy Windows PowerShell 5.1 scripts, you may encounter Get-WmiObject examples. However, PowerShell 7+ does not include the Get-WmiObject cmdlet, so you should use Get-CimInstance for all modern scripts and automation cases.

Find Volumes Running Low on Free Space
In real-world environments, you may be interested in identifying disks that are running low on free space rather than simply displaying all volumes. PowerShell makes it easy to filter volumes based on available capacity thresholds.
Example 1: Find Volumes with Less Than 10% Free Space
The following command displays volumes that have less than 10 percent of their total capacity remaining:
Get-Volume |
Where-Object {
$_.SizeRemaining / $_.Size -lt 0.1
} |
Sort-Object SizeRemaining
Example 2: Display Free Space Percentage
The following example calculates and displays the percentage of free space available on each volume:
Get-Volume |
Select-Object DriveLetter,
@{
Name='FreeSpacePercent'
Expression={
[math]::Round(
($_.SizeRemaining / $_.Size) * 100,
2
)
}
}

Example 3: Filter Local Disks Using CIM
The following method works on local/remote machines and returns only fixed disks with less than 10 percent free space remaining:
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Where-Object {
($_.FreeSpace / $_.Size) -lt 0.1
}
In order to display disk space in GB, run the following command:
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID,
@{
Name='SizeGB'
Expression={[math]::Round($_.Size/1GB,2)}
},
@{
Name='FreeGB'
Expression={[math]::Round($_.FreeSpace/1GB,2)}
}
Example 4: Show Volumes with Less Than 20 GB Free
The following command returns all volumes with less than 20 GB of free space:
Get-Volume |
Where-Object {
$_.SizeRemaining -lt 20GB
}
Tip. Monitoring solutions typically use threshold-based checks (for example, less than 10% free space or less than 20 GB remaining) rather than displaying raw disk statistics. Note that these thresholds can be integrated into scheduled PowerShell scripts, monitoring platforms, or alerting systems.
Up to this point, the examples focused on one-time disk space checks using built-in PowerShell commands. In many environments, these commands are sufficient for daily administration.
If you need to collect disk space info from multiple machines, generate reports, or integrate the results into monitoring workflows, you can wrap the logic into a reusable PowerShell function.
Most Common Disk Space Commands
For quick administrative tasks, the following commands are usually sufficient:
You can check all volumes with the command:
Get-Volume
In order to check local disks only, use the following command:
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3"
You can find volumes with less than 10% free space using the command:
Get-Volume |
Where-Object {
$_.SizeRemaining / $_.Size -lt 0.1
}
To query a remote server, use the following command:
Get-CimInstance Win32_LogicalDisk `
-ComputerName SRV01 `
-Filter "DriveType=3"
If these commands meet your requirements, there is no need to use a custom function. The script below is intended for larger environments where the same check must be performed repeatedly across multiple servers.
Advanced: Create a Reusable Disk Space Reporting Function
Running the PowerShell check disk space commands manually is suitable for ad-hoc work. But it would be best to convert the commands into a reusable script or function that anyone can use without modifying the code.
Hereโs a PowerShell script called Get-DiskSpace. You can also download this script from this Gist. This function can retrieve the disk space information on local and remote computers and display them in an easy-to-understand result.
Function Get-DiskSpace {
[CmdletBinding()]
param (
[Parameter()]
[String[]]
$ComputerName = $env:COMPUTERNAME
)
# Drive type lookup table
$driveType = @{
0 = 'Unknown'
1 = 'No Root Directory'
2 = 'Removable Disk'
3 = 'Local Disk'
4 = 'Network Drive'
5 = 'Compact Disc'
6 = 'RAM Disk'
}
$result = [System.Collections.ArrayList]@()
foreach ($computer in $ComputerName) {
try {
if ($localLogicalDisks = Get-CimInstance -Class Win32_LogicalDisk -ComputerName $computer -Property * -ErrorAction Stop) {
$result.AddRange($localLogicalDisks)
if (($localLogicalDisks.DriveType) -notcontains 4) {
if ($mappedLogicalDisks = Get-CimInstance -Class Win32_MappedLogicalDisk -ComputerName $computer -Property * -ErrorAction Stop) {
$result.AddRange($mappedLogicalDisks)
}
}
}
}
catch {
"[ERROR][$computer] : $($_.exception.message)" | Out-Default
}
}
if ($result) {
$result | ForEach-Object {
[PSCustomObject]@{
ComputerName = $_.SystemName
DeviceID = $_.DeviceID
VolumeName = $_.VolumeName
DriveType = $(
if ($_.DriveType) {
$driveType[$([int]$_.DriveType)]
}
else {
$driveType[4]
}
)
SizeGB = $(
if ($null -ne $_.Size) {
[System.Math]::Round(($_.Size / 1GB), 2)
}
else {
$null
}
)
UsedSpaceGB = $(
if ($null -ne $_.Size -and $null -ne $_.FreeSpace) {
[System.Math]::Round(
(($_.Size - $_.FreeSpace) / 1GB),
2
)
}
else {
$null
}
)
FreeSpaceGB = $(
if ($null -ne $_.FreeSpace) {
[System.Math]::Round(($_.FreeSpace / 1GB), 2)
}
else {
$null
}
)
FreeSpacePercent = $(
if ($_.Size -gt 0) {
[System.Math]::Round(
(($_.FreeSpace / $_.Size) * 100),
2
)
}
else {
$null
}
)
}
}
}
} Note. The function performs an additional query against the Win32_MappedLogicalDisk class only when no network drives (DriveType = 4) are returned by Win32_LogicalDisk. This helps you to capture mapped network drives that are often missing from remote CIM/WMI queries while avoiding duplicate entries when network drives are already present in the results.
How to Use this PowerShell Check Disk Space Function?
Save the script on your computer and name it Get-DiskSpace.ps1. Open PowerShell and change the working directory to where you saved the script.
When you run the script without the -ComputerName parameter, only the local computer will be queried by default.
.\Get-DiskSpace.ps1 | Format-Table

To query one or more computers, specify the computer names in the -ComputerName parameter.
.\Get-DiskSpace.ps1 -ComputerName DC1,DC2 | Format-Table

What happens if you specify a wrong or non-existing computer name? The script will display an error and skip that computer. For example, I included a DC3 in the query, but it does not exist.

You can also output the result to a CSV, JSON, Text, and other file formats by piping to the corresponding conversion cmdlets, like, Export-Csv, ConvertTo-JSON, Out-File, etc. Take it further by exporting and formatting the report in beautiful HTML files.
Practical Reporting and Automation Examples
In production environments, disk space info is often exported, scheduled, or integrated into monitoring workflows. The following examples demonstrate common admin tasks.
Example 1: Export Disk Space Report to CSV
The following command exports volume info to a CSV file that can be opened in Microsoft Excel/imported into reporting systems:
Get-Volume |
Select-Object DriveLetter,
@{
Name='FreeSpaceGB'
Expression={
[math]::Round(
$_.SizeRemaining / 1GB,
2
)
}
} |
Export-Csv C:\Reports\DiskSpace.csv -NoTypeInformation
Example 2: Generate an HTML Report
You can use HTML reports because they are useful for dashboards, documentation, or email distribution:
Get-Volume |
Select-Object DriveLetter,
FileSystemLabel,
Size,
SizeRemaining |
ConvertTo-Html |
Out-File C:\Reports\DiskSpaceReport.html
Example 3: Find Critical Volumes
The following example identifies volumes with less than 10 percent free space remaining:
Get-Volume |
Where-Object {
$_.SizeRemaining / $_.Size -lt 0.1
}
In rare cases, some devices (such as empty optical drives) may report a volume size of 0. When using percentage-based calculations in production scripts, you should consider adding a check to avoid division-by-zero errors.
Example 4: Generate Alert-Friendly Output
The output can be consumed by monitoring systems/scheduled scripts:
Get-Volume |
Where-Object {
$_.SizeRemaining / $_.Size -lt 0.1
} |
Select-Object DriveLetter,
@{
Name='FreePercent'
Expression={
[math]::Round(
($_.SizeRemaining / $_.Size) * 100,
2
)
}
}
Example 5: Schedule a Daily Disk Space Check
To automate disk space monitoring, you need to save the script as a .ps1 file and execute it through Windows Task Scheduler on a daily/hourly basis. This method is commonly used to generate reports and identify low disk space conditions before they impact services.
Common Disk Space Commands
| Task | Recommended Command |
|---|---|
| Check all volumes | Get-Volume |
| Check physical disks | Get-Disk |
| Check partitions | Get-Partition |
| Check storage hardware | Get-PhysicalDisk |
| Check remote servers | Get-CimInstance |
| Find low disk space volumes | Get-Volume + Where-Object |
| Generate reports | Export-Csv / ConvertTo-Html |
Conclusion
Using the above PowerShell commands and script, you can effortlessly keep track of disk space on your Windows machines, ensuring that you never run out of space and maintain optimal system performance.
In conclusion, PowerShell is a versatile tool simplifying disk space monitoring and management. Whether you want to check individual volumes, all drives, or multiple servers, PowerShell provides various methods to make the process efficient and effective.
Keeping an eye on disk space is an essential part of system maintenance, and with PowerShell, it becomes a breeze. You can also export PowerShell output to CSV, HTML, JSON, or monitoring platforms, making it suitable for enterprise reporting and automation cases. Happy scripting!
Why should I use Get-CimInstance instead of Get-WmiObject?
Get-WmiObject is a legacy cmdlet available only in Windows PowerShell 5.1 and earlier. Get-CimInstance is the recommended modern alternative and works in PowerShell 7+.
What are Get-Disk, Get-Partition, and Get-PhysicalDisk used for?
These cmdlets provide storage infrastructure information:
- Get-Disk โ physical disk details such as size and partition style.
- Get-Partition โ partition layout and drive letters.
- Get-PhysicalDisk โ hardware-level details including health status and media type.
They are primarily used for storage management and troubleshooting rather than checking free space.
How can I automate disk space monitoring?
Save your PowerShell script as a .ps1 file and schedule it with Windows Task Scheduler. You can configure it to run daily or hourly and export reports or generate alerts when free space drops below a specified threshold.
When should I use a custom disk space reporting function?
A custom function is useful when you need to:
- Collect disk space information from multiple servers.
- Generate reusable reports.
- Export results to CSV, JSON, or HTML.
- Integrate disk space checks into monitoring and automation workflows.
- Include both local and mapped network drives in the results.
