EclipseRMM green eclipse symbolEclipseRMM

FIELD NOTES / WINDOWS DEVICE MANAGEMENT

How to Check Disk Space with PowerShell (Local and Remote Windows Computers)

To check disk space with PowerShell on a Windows computer, run Get-Volume. It lists each volume with its drive letter, file system, health status, SizeRemaining (free space) and Size. For a version that also works well against remote computers and in reports, query the Win32_LogicalDisk class with Get-CimInstance and convert the FreeSpace and Size values from bytes to GB. This guide shows three read-only methods, how to calculate percent free, and a script that flags low disk space across many Windows PCs.

Method 1: Get-Volume (quickest on one computer)

Get-Volume comes from the Storage module. Microsoft describes it as returning "a Volume object or a set of Volume objects that match the specified criteria". With no parameters it returns all volumes; with -DriveLetter it returns just the ones you name:

# All volumes on this computer
Get-Volume

# Only drive C
Get-Volume -DriveLetter C

The default table already shows SizeRemaining and Size in readable units, plus HealthStatus. Behind the table, both values are numbers of bytes, which matters as soon as you sort, filter or calculate. To list volumes that have a drive letter, with free space in GB:

Get-Volume |
    Where-Object DriveLetter |
    Select-Object DriveLetter, FileSystemLabel, HealthStatus,
        @{ Name = 'FreeGB'; Expression = { [math]::Round($_.SizeRemaining / 1GB, 1) } },
        @{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 1) } }

1GB is a built-in PowerShell numeric constant equal to 1,073,741,824 bytes, so dividing a byte count by it gives the size in GB.

Method 2: Get-PSDrive (built into PowerShell)

Get-PSDrive is part of the core Microsoft.PowerShell.Management module, so it is available even where the Storage module isn't. Limit it to file system drives to get the Used (GB) and Free (GB) columns:

Get-PSDrive -PSProvider FileSystem

# Just drive C (no colon after the letter)
Get-PSDrive C

Two points from Microsoft's documentation explain the output. First, the FileSystem provider includes mapped network drives and temporary drives created with New-PSDrive, not only local disks, so a network share can appear in the list. Second, mapped drives are specific to a user account: a session started with Run as administrator may not see drives that were mapped in a normal session. For an inventory of local disks, the next method is more predictable.

Method 3: Win32_LogicalDisk with Get-CimInstance

The Win32_LogicalDisk class represents "a data source that resolves to an actual local storage device" on a Windows computer. Its FreeSpace and Size properties are in bytes, and its DriveType property tells you what kind of drive each entry is:

Filtering on DriveType = 3 keeps only local hard disks, which is usually what you want for a disk space check. Pass the filter to -Filter (without the word WHERE) so the filtering happens on the queried computer rather than after every object has been returned:

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType = 3" |
    Select-Object DeviceID, VolumeName,
        @{ Name = 'FreeGB';  Expression = { [math]::Round($_.FreeSpace / 1GB, 1) } },
        @{ Name = 'SizeGB';  Expression = { [math]::Round($_.Size / 1GB, 1) } },
        @{ Name = 'PctFree'; Expression = { [math]::Round($_.FreeSpace / $_.Size * 100, 1) } }

The output is one row per drive, such as C:, with free space, total size and percent free. Microsoft's own example for this class uses the older Get-WmiObject cmdlet; Get-CimInstance reads the same class and is the cmdlet available in PowerShell 7 as well as Windows PowerShell 5.1.

Which method should you use?

Find low disk space with a threshold

A disk space check is most useful when it answers a yes/no question: which drives need attention? Pick thresholds that fit your environment. The example below flags a drive when it has less than 10 percent free or less than 15 GB free, so that both small and very large disks are caught. These numbers are an example, not a Microsoft recommendation.

$minPct = 10
$minGB  = 15

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType = 3" |
    Where-Object { $_.Size -gt 0 } |
    ForEach-Object {
        $freeGB = [math]::Round($_.FreeSpace / 1GB, 1)
        $pct    = [math]::Round($_.FreeSpace / $_.Size * 100, 1)
        [pscustomobject]@{
            Drive   = $_.DeviceID
            FreeGB  = $freeGB
            PctFree = $pct
            Low     = ($pct -lt $minPct) -or ($freeGB -lt $minGB)
        }
    }

The Where-Object { $_.Size -gt 0 } line avoids a divide-by-zero error on a drive that reports no size. The command only reads; it doesn't delete or move anything.

Check disk space on remote computers

When you give Get-CimInstance a -ComputerName, Microsoft's documentation says it "creates a temporary session to the specified computer using the WsMan protocol", which is WinRM. For several queries against the same computers, Microsoft recommends a CIM session for better performance. Get-Volume accepts the same sessions through its -CimSession parameter.

$computers = 'PC-01', 'PC-02', 'SRV-FILE01'
$sessions  = New-CimSession -ComputerName $computers -ErrorAction SilentlyContinue

$report = Get-CimInstance -CimSession $sessions -ClassName Win32_LogicalDisk `
              -Filter "DriveType = 3" -Property DeviceID, FreeSpace, Size |
    Where-Object { $_.Size -gt 0 } |
    Select-Object PSComputerName, DeviceID,
        @{ Name = 'FreeGB';  Expression = { [math]::Round($_.FreeSpace / 1GB, 1) } },
        @{ Name = 'PctFree'; Expression = { [math]::Round($_.FreeSpace / $_.Size * 100, 1) } }

# Lowest free space first
$report | Sort-Object PctFree | Format-Table -AutoSize

# Computers that returned nothing (not reachable over WinRM, or access denied)
$computers | Where-Object { $_ -notin $report.PSComputerName }

$sessions | Remove-CimSession

-Property asks only for the three values the report needs, which Microsoft notes "reduces the size of the object" returned over the network. Always review the last list by hand: a computer that is missing from the report has not been checked, and it is not safe to assume its disks are fine.

This approach needs WinRM to be enabled and reachable on each target, and an account with permission on it. That is easy on a domain network and harder on laptops at home or devices spread across several sites. Our guide to PowerShell remote management without RDP compares WinRM, SSH and agent-based options.

Checking disk space through an RMM agent

With an agent-based tool the command is delivered to an installed agent, so the target doesn't need to accept inbound WinRM connections. In EclipseRMM's PowerShell RMM, you run authorized PowerShell, such as the Win32_LogicalDisk query above, on an enrolled Windows device and review the output, errors and completion status in the portal. The product documentation highlights a few points that apply here:

For more commands that are safe to run first, see our list of read-only PowerShell commands, and for the same pattern applied to services, how to check service status with PowerShell.

FAQ

Why does my script show huge numbers instead of GB?

FreeSpace, Size and SizeRemaining are in bytes. Divide by 1GB and round with [math]::Round() to get readable values. Do the conversion in a calculated property, as in the examples, so you can still sort on the number.

Why doesn't Win32_LogicalDisk show my mapped network drive?

Microsoft notes that Win32_LogicalDisk is meant for local disk drives and points to the Win32_MappedLogicalDisk class for mapped network drives. Mapped drives are also tied to the user session that created them, so a check that runs under a different account may not see them.

Does checking disk space change anything on the computer?

No. Get-Volume, Get-PSDrive and Get-CimInstance only read. Cleaning up space is a separate step; decide what to remove only after you have reviewed the report.

How do I check one folder's size rather than the whole drive?

Drive-level free space doesn't tell you which folder is large. A common approach is Get-ChildItem -Path C:\Path -Recurse -File | Measure-Object -Property Length -Sum, which adds up file sizes in bytes. It can take a long time on large folders, and files you don't have permission to read produce errors and are not counted.