PowerShell can print free disk space, the size of one folder including its subfolders, and the largest files under a path. Get-CimInstance reads the volume. Get-ChildItem plus Measure-Object adds up file lengths. Every command on this page only asks Windows for numbers. Run them in a normal window first. Elevate only if you want the listing to see more of a system drive.
Copy the commands carefully. Do not add Remove-Item, del, or Clear-Content. A recursive delete is not a size check.
Open PowerShell
Right-click Start and choose Windows Terminal or PowerShell. On Windows 10, Start, then Windows PowerShell, also works. Windows PowerShell 5.1 and PowerShell 7 both understand the cmdlets used here. Commands that need the -Parallel parameter are not used, so you do not need PowerShell 7 for these checks.
See free space and capacity
Get-PSDrive -PSProvider FileSystem
Get-PSDrive lists file-system drives the session can see, including Used and Free counts in bytes. Mapped network drives may appear beside local disks. The numbers are a quick look, not a full category breakdown.
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID, VolumeName, FileSystem,
@{Name='SizeGB';Expression={[math]::Round($_.Size/1GB,2)}},
@{Name='FreeGB';Expression={[math]::Round($_.FreeSpace/1GB,2)}},
@{Name='UsedGB';Expression={[math]::Round(($_.Size-$_.FreeSpace)/1GB,2)}}
Expected result: one row per local fixed disk, with device ID such as C:, the file system, and three rounded gigabyte figures. DriveType=3 keeps removable disks and network drives out of this particular list. Size and FreeSpace come from the logical disk in bytes. PowerShell’s 1GB is 1,024³ bytes.
Limitation: this is the volume view. It does not say which folder is responsible. It also will not explain shadow-copy space beyond what the file system already counts as used. For the click-path version of the same numbers, see check disk space.
Get the size of one folder, including subfolders
$path = 'C:\Users\Public'
$sum = Get-ChildItem -LiteralPath $path -Recurse -File -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum
[pscustomobject]@{
Path = $path
Files = $sum.Count
SizeGB = [math]::Round(($sum.Sum / 1GB), 2)
}
Change $path to the folder you care about. -File skips directory entries. -Recurse walks subfolders. -Force includes hidden files. -ErrorAction SilentlyContinue lets the walk continue when a file is denied. Measure-Object adds the Length property, which is the logical file size in bytes.
Expected result: a small object with the path, a file count, and a gigabyte total. A folder of a few documents may show 0 after rounding to two decimals. Drop to megabytes if you need that detail:
[math]::Round(($sum.Sum / 1MB), 1)
Limitations are important. Access-denied files are missing, so the total can be low. The walk can take a long time on C:\ or on a folder with millions of files. Reparse points, such as some junctions, can make a careless recursive listing visit a tree more than once or leave the folder you named. If a total looks implausibly larger than the drive, stop and check the path. This sum is logical size, not “size on disk,” so compression and cluster rounding will not match a Properties dialog exactly. Compare the method with check folder size.
List immediate child folders and their sizes
$root = 'C:\Users\Public'
Get-ChildItem -LiteralPath $root -Directory -Force -ErrorAction SilentlyContinue |
ForEach-Object {
$sum = Get-ChildItem -LiteralPath $_.FullName -Recurse -File -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum
[pscustomobject]@{
Folder = $_.Name
SizeGB = [math]::Round(($sum.Sum / 1GB), 2)
}
} | Sort-Object SizeGB -Descending
Expected result: the subfolders of $root, largest first, each with its own nested total. This is the PowerShell version of a folder size view. It answers “powershell disk usage by folder” for one parent. It does not draw a treemap. A visual pass over the same parent is described on the folder size analyzer page.
Limitation: each child triggers its own recursive walk, so a broad parent is slow. Errors inside a child are silenced, and that child then looks smaller than it is. Directory links under the parent inherit the reparse-point caution from the previous section.
Find the largest files under a path
Get-ChildItem -LiteralPath 'C:\Users\Public' -Recurse -File -Force -ErrorAction SilentlyContinue |
Sort-Object Length -Descending |
Select-Object -First 20 FullName, @{Name='SizeMB';Expression={[math]::Round($_.Length/1MB,1)}}
Expected result: up to 20 files, biggest first, with full path and size in megabytes. Point it at a user profile or a data folder rather than all of C:\ unless you are prepared to wait and to see system paths. Finding large files in Explorer is covered in find large files. The script is the same idea with an explicit threshold of “top 20.”
Limitation: Sort-Object waits for the listing to finish before it can rank the files. It holds those file objects in memory. On a huge tree, prefer a narrower path.
What these commands do not change
None of the examples write files, change permissions, or clear the Recycle Bin. They can still have side effects you should expect from any read: disk activity while Windows opens directories, and errors in the console if you remove -ErrorAction SilentlyContinue. Leaving that parameter off is useful when you want to see which folders were skipped. It does not make the total more complete.
Avoid Get-ChildItem C:\ -Recurse as a first experiment on a PC you need to keep using. Start with C:\Users\Public or a folder of your own. Looking at someone else’s profile, or at a drive you do not administer, may be restricted by permissions and by policy.
When the window is the better tool
Storage settings are still the clearer view when you want Windows cleanup categories. A treemap is easier when you want to see nesting without reading a table. PowerShell is the better view when you need a number you can paste into a note, or the same check next week with only the path changed. These commands do not configure SpaceSniffer, and SpaceSniffer does not replace them.
Related guides
Questions about PowerShell sizes
How do I get a folder size in PowerShell including subfolders?
Pipe Get-ChildItem -Recurse -File for that path into Measure-Object Length -Sum. The Sum property is the total of file lengths in bytes.
How do I show the result in gigabytes?
Divide the byte total by 1GB and round it. Use 1MB when the folder is small.
Why is the PowerShell total smaller than Properties?
The command skipped files it could not read, or you pointed it at a different path. Properties can also report size on disk, which is not the same as the sum of Length.
Can these commands free disk space?
No. They only print measurements. Cleanup steps belong in Windows Storage and in the free-space guide.
Sources
- Get-PSDrive, Microsoft Learn.
- Get-ChildItem, Microsoft Learn.
- Measure-Object, Microsoft Learn.
- Win32_LogicalDisk, Microsoft Learn.