Last active
November 26, 2022 15:43
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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