Create a Windows disk-space report with PowerShell
Need a quick view of disk space before an update or support call? This script lists the computer's local fixed drives and can save the same information as a CSV.
What it does
The script queries Win32_LogicalDisk, selecting fixed drives (DriveType=3). It reports the drive letter, label, capacity, free space and free percentage. Values labelled GiB use a binary conversion; they may differ from another tool's GB display. See Microsoft's Win32_LogicalDisk reference.
It reads disk information without changing it. Only the optional -CsvPath parameter writes a report file. It doesn't inspect remote computers, network shares, volumes without drive letters or disk hardware health.
Get the script
Requirements: Windows with Windows PowerShell 5.1 or PowerShell 7 and access to local CIM information. No elevation is normally needed for this local query.
Read through the script before running it on your PC.
# Lists local fixed drives with drive letters. Does not modify disks.
# Optional: pass -CsvPath to create a new report file (never overwrites).
[CmdletBinding()]
param(
[string]$CsvPath
)
$disks = @(Get-CimInstance -ClassName Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction Stop)
if ($disks.Count -eq 0) {
Write-Warning 'No local fixed drives were returned.'
return
}
$report = @($disks | Sort-Object DeviceID | ForEach-Object {
[pscustomobject]@{
Computer = $env:COMPUTERNAME
Drive = $_.DeviceID
Label = $_.VolumeName
SizeGiB = if ($null -ne $_.Size) { [math]::Round($_.Size / 1GB, 2) } else { $null }
FreeGiB = if ($null -ne $_.FreeSpace) { [math]::Round($_.FreeSpace / 1GB, 2) } else { $null }
FreePercent = if ($_.Size -gt 0 -and $null -ne $_.FreeSpace) {
[math]::Round(100 * $_.FreeSpace / $_.Size, 1)
} else { $null }
}
})
if ($CsvPath) {
$report | Export-Csv -LiteralPath $CsvPath -NoTypeInformation -Encoding UTF8 -NoClobber -ErrorAction Stop
}
$report
Run it
- Download the
.ps1file, or copy the code into Notepad and save it asget-disk-space-report.ps1using All files as the file type. - Open PowerShell and change to the folder containing the script.
- Run it:
.\get-disk-space-report.ps1
To create a new CSV in the current folder:
.\get-disk-space-report.ps1 -CsvPath '.\disk-space-report.csv'
Choose an existing writable folder. The export refuses to overwrite an existing file; use another filename for your next report. See Microsoft's Export-Csv reference.
If execution policy blocks the file, use your organisation's approved script process. You can also paste the reviewed code into an interactive PowerShell session where permitted. The script doesn't change execution policy.
Read the result
Check both FreeGiB and FreePercent against the workload's requirements. A small percentage on a large drive can still represent substantial space, while an installation may need more than a small drive has available. This report sets no universal “healthy” threshold.
Verify
Compare a listed drive with its properties in File Explorer. Allow for rounding and changes while applications are running. If you requested CSV output, open the file and check that it contains the same drive letters and columns as the console result.
If the query returns an access or CIM error, investigate that message rather than interpreting it as a full disk. Query behaviour is covered by Microsoft's Get-CimInstance reference.