PowerShell one-liners for getting drive/folder (storage) utilization.
#
# Get drive utilization using PSDrive
Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Used -gt 0} |
Select-Object -Property Root, @{Name = 'SizeGB'; Expression = {($_.Used + $_.Free) / 1GB -as [Int]}},
@{Name = 'UsedGB'; Expression = {($_.Used / 1GB) -as [Int]}},
@{Name = 'FreeGB'; Expression = {($_.Free / 1GB) -as [Int]}},
@{Name = 'PctFree'; Expression = {[Math]::Round(($_.Free / ($_.Used + $_.Free)) * 100, 2)}}
# Root : /
# SizeGB : 233
# UsedGB : 184
# FreeGB : 50
# PctFree : 21.34
# Root : /var/folders/8w/fdvj1tp950n3dyk404dpjtyh0000gn/T/
# SizeGB : 233
# UsedGB : 184
# FreeGB : 50
# PctFree : 21.34
#
# Get folder utilization for a given directory:
Get-ChildItem -Path . -File -Recurse -Force |
Measure-Object Length -Sum -Maximum -Average |
Select-Object @{Name = 'Total Files'; Expression = {$_.Count}},
@{Name = 'Largest File(MB)'; Expression = {'{0:F2}' -f ($_.Maximum / 1MB)}},
@{Name = 'Average Size(MB)'; Expression = {'{0:F2}' -f ($_.Average / 1MB)}},
@{Name = 'Total Size(MB)'; Expression = {'{0:F2}' -f ($_.Sum / 1MB)}}
# Total Files Largest File(MB) Average Size(MB) Total Size(MB)
# ----------- ---------------- ---------------- --------------
# 4749 30.81 0.04 210.70