How to Get File Size in PowerShell (5 Methods)

Disk space alerts fire at 3 AM. A folder that should hold weekly logs is somehow 50GB. A single file is blocking a backup job. These are the moments when you need to quickly measure file sizes with PowerShell — and the tool handles it in seconds without opening File Explorer. This guide shows 5 reliable methods to get file size in PowerShell, from single file lookups to recursive folder size reports formatted in KB, MB, and GB.
Method 1: Length Property
Every file returned by Get-ChildItem or Get-Item has a Length property containing the file size in bytes:
# Get size of a single file in bytes
$file = Get-Item 'C:\Logs\app.log'
$file.Length
# Size of a specific file directly
(Get-Item 'C:\Logs\app.log').Length
10485760
The Length property is always in bytes. Directories do not have a Length property — it will be $null for folders. Use Get-Item -Path path -File or check PSIsContainer if you’re unsure whether a path is a file or directory.
Method 2: Get-ChildItem with Select-Object
Combine Get-ChildItem with Select-Object to get file sizes alongside names in one clean output:
# List all files with sizes
Get-ChildItem 'C:\Logs' -File |
Select-Object Name, Length |
Sort-Object Length -Descending
# Filter to specific extension
Get-ChildItem 'C:\Users\Public\Documents' -Recurse -File -Filter '*.pdf' |
Select-Object Name, Length |
Sort-Object Length -Descending
Name Length
---- ------
system.log 16777216
app.log 10485760
error.log 4194304
debug.log 131072
Method 3: Convert Bytes to KB, MB, GB
PowerShell understands KB, MB, and GB multipliers in expressions. Use them with calculated properties for human-readable output:
Get-ChildItem 'C:\Logs' -File |
Select-Object Name,
@{ Name='SizeKB'; Expression={ [math]::Round($_.Length / 1KB, 1) } },
@{ Name='SizeMB'; Expression={ [math]::Round($_.Length / 1MB, 2) } } |
Sort-Object { $_.SizeKB } -Descending |
Format-Table -AutoSize
# Single file with formatted size
$file = Get-Item 'C:\Logs\system.log'
'Size: {0:N2} MB' -f ($file.Length / 1MB)
Name SizeKB SizeMB
---- ------ ------
system.log 16384.0 16.00
app.log 10240.0 10.00
error.log 4096.0 4.00
debug.log 128.0 0.13
Size: 16.00 MB
PowerShell’s built-in multipliers: 1KB = 1024, 1MB = 1048576, 1GB = 1073741824, 1TB = 1099511627776. Use these in conditions too: Where-Object { $_.Length -gt 10MB }.
Method 4: Get Total Folder Size
Combine Get-ChildItem -Recurse with Measure-Object to sum all file sizes in a folder:
# Total size of C:\Logs and all subfolders
$total = Get-ChildItem 'C:\Logs' -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum
'Total size: {0:N2} MB' -f ($total.Sum / 1MB)
'File count: {0}' -f $total.Count
# Size of multiple specific folders
'C:\Logs', 'C:\Backup', 'C:\Scripts' | ForEach-Object {
$size = (Get-ChildItem $_ -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
Folder = $_
SizeGB = [math]::Round($size / 1GB, 3)
}
}
Total size: 30.13 MB
File count: 12
Folder SizeGB
------ ------
C:\Logs 0.030
C:\Backup 2.147
C:\Scripts 0.001
Method 5: One-Line Recursive Size Report
The most useful pattern for disk space investigation — find the largest subdirectories:
# Top 10 largest immediate subdirectories of C:\
Get-ChildItem 'C:\' -Directory | ForEach-Object {
$size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
Folder = $_.Name
SizeGB = [math]::Round($size / 1GB, 2)
}
} | Sort-Object SizeGB -Descending | Select-Object -First 10 | Format-Table -AutoSize
Folder SizeGB
------ ------
Windows 23.47
Users 18.92
Program Files 12.34
ProgramData 5.81
Logs 0.03
Common Errors and Fixes
-
Length is null on directories — use Get-ChildItem -File: Accessing
.Lengthon a directory object returns$null. Always add-FiletoGet-ChildItemwhen you only want file sizes, or check$_.PSIsContainer -eq $falsebefore accessingLength. -
Permission denied on system folders:
Measure-Objectstops summing if it hits a folder where access is denied. Add-ErrorAction SilentlyContinuetoGet-ChildItemto skip inaccessible folders and continue summing the rest. The total will be a lower bound rather than the true size.
Related Cmdlets / See Also
Wrapping Up
Getting file sizes in PowerShell is simple: use the Length property for individual files, Measure-Object -Sum for folder totals, and calculated properties with / 1MB or / 1GB for human-readable output. Add -ErrorAction SilentlyContinue when recursing to handle permission errors gracefully. Your next step: run the top-10 largest subdirectories report on your system’s largest drive.


