In Windows 11, the native File Explorer purposefully leaves the “Size” column blank for directories in Details view. Because calculating folder sizes across deep directory trees requires reading thousands of file allocation table entries, Windows omits this data to preserve disk performance and prevent system sluggishness. However, when auditing local storage or hunting down bloated directories consuming SSD space, knowing the exact size of folders is essential.
Fortunately, PowerShell makes it easy to calculate, aggregate, and format directory sizes with precision. In this guide, you will learn how to calculate folder and directory sizes in Windows 11 using PowerShell cmdlets, format raw byte counts into readable megabytes and gigabytes, and sort subfolders from largest to smallest.
Why Use PowerShell for Directory Size Audits?
While third-party graphical tools exist, PowerShell offers significant advantages:
- Zero Software Footprint: Built directly into every Windows 11 installation without requiring third-party utility installations.
- Custom Filtering: Filter by file age, extensions, or specific subtrees while omitting irrelevant files.
- Automation & Scripting: Easily pipe results to CSV files, format outputs into tables, or schedule automatic disk usage alerts.
Step 1: Calculate the Total Size of a Single Folder
The foundation of folder size calculation in PowerShell combines two cmdlets: Get-ChildItem (to collect files recursively) and Measure-Object (to sum file lengths).
Launch PowerShell (press Win + X and select Terminal), then run the following command:
(Get-ChildItem -Path "C:\Users\YourUsername\Documents" -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
This command returns the total size in raw bytes. The parameters accomplish the following:
-Recurse: Scans all nested subfolders within the target directory.-File: Ensures directory objects themselves are excluded from measurement, evaluating only file payloads.-Force: Includes hidden and system files that standard enumeration skips.-ErrorAction SilentlyContinue: Suppresses benign access denial warnings when encountering locked files.
Step 2: Format Bytes into Megabytes (MB) and Gigabytes (GB)
Reading nine-digit byte numbers is impractical. You can use PowerShell’s built-in unit constants (1MB and 1GB) and the [math]::Round method to format values into clean decimal figures:
$folder = "C:\Users\YourUsername\Downloads"
$sizeInBytes = (Get-ChildItem -Path $folder -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
Folder = $folder
SizeInMB = [math]::Round($sizeInBytes / 1MB, 2)
SizeInGB = [math]::Round($sizeInBytes / 1GB, 2)
}
This returns a structured object displaying both megabyte and gigabyte metrics rounded to two decimal places.
Step 3: Calculate and Sort All Subfolders in a Directory
To identify which specific subfolder is consuming your storage, iterate through each immediate child folder and sort the output in descending order:
$targetPath = "C:\Users\YourUsername"
Get-ChildItem -Path $targetPath -Directory | ForEach-Object {
$subfolder = $_.FullName
$measure = Get-ChildItem -Path $subfolder -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum
[PSCustomObject]@{
FolderName = $_.Name
SizeInGB = [math]::Round(($measure.Sum / 1GB), 2)
FileCount = $measure.Count
}
} | Sort-Object -Property SizeInGB -Descending | Format-Table -AutoSize
This script scans each top-level directory, tallies the nested contents, calculates file counts, and produces a neatly aligned terminal table listing the largest directories first.
Step 4: Create a Reusable PowerShell Function
If you perform storage audits regularly, add a custom function to your PowerShell profile (notepad $PROFILE) so you can run it from any location like a standard command:
function Get-FolderSize {
[CmdletBinding()]
param(
[Parameter(Mandatory=$false, Position=0)]
[string]$Path = (Get-Location)
)
Get-ChildItem -Path $Path -Directory | ForEach-Object {
$folderSize = (Get-ChildItem -Path $_.FullName -Recurse -File -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
Folder = $_.Name
SizeGB = [math]::Round(($folderSize / 1GB), 2)
SizeMB = [math]::Round(($folderSize / 1MB), 2)
FullPath = $_.FullName
}
} | Sort-Object -Property SizeGB -Descending | Format-Table -AutoSize
}
Once added and saved, simply typing Get-FolderSize in any terminal window audits the current working directory instantly.
For more administrative techniques in Windows 11, explore how to audit hardware, BIOS, and motherboard specifications in Windows 11 using PowerShell Get-CimInstance, or check our guide on how to locate executables and script paths in Windows 11 using the where command.
Frequently Asked Questions
Why does PowerShell report access denied on certain folders?
System folders (such as System Volume Information or protected user profiles) require administrative privileges. To minimise permission failures, launch PowerShell with Run as administrator and always include -ErrorAction SilentlyContinue.
Is this command faster than right-clicking a folder in File Explorer?
Yes. Right-clicking a folder and viewing Properties in File Explorer triggers UI thread updates that slow down large counts. PowerShell performs pure non-blocking file table queries, making it considerably faster when processing directories containing tens of thousands of items.
Can I export these results to an Excel or CSV file?
Yes. Simply replace Format-Table -AutoSize at the end of the command pipeline with Export-Csv -Path "C:\FolderSizes.csv" -NoTypeInformation to save the results directly into a spreadsheet-ready file.