Skip to content

Instantly share code, notes, and snippets.

@fdcastel
Last active November 26, 2022 15:43
Show Gist options
  • Save fdcastel/920fb43445f5868035af4612c9029545 to your computer and use it in GitHub Desktop.
Save fdcastel/920fb43445f5868035af4612c9029545 to your computer and use it in GitHub Desktop.
Retrieve disk space used by files and subfolders of a given folder (in GB).
function Get-FolderUsage([String]$Folder) {
[PSCustomObject]@{
FullName=Join-Path -Path $Folder -ChildPath '*';
SizeGb=[int]((Get-ChildItem -File $Folder | Measure-Object -Property Length -Sum).Sum / 1GB)
} | Write-Output
Get-ChildItem -Directory -Path $Folder |
ForEach-Object {
[PSCustomObject]@{
FullName=$_.FullName;
SizeGb=[int]((Get-ChildItem $_.FullName -Recurse | Measure-Object -Property Length -Sum).Sum / 1GB)
} | Write-Output
}
}
Set-Alias gfu -Value Get-FolderUsage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment