Created
April 18, 2023 21:45
-
-
Save thomas694/676f375d9698468d174633e57b80bdfd to your computer and use it in GitHub Desktop.
Shows used space per file type of files in first-level subfolders of the specified path
This file contains hidden or 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
| <# | |
| .SYNOPSIS | |
| Shows used space per file type in all first-level subfolders. | |
| .DESCRIPTION | |
| Shows used space per file type of files in first-level subfolders of the specified path. | |
| Example usages: | |
| PS> sum_up_types_per_folder.ps1 C:\BasePath\ | |
| PS> sum_up_types_per_folder.ps1 C:\BasePath\ 1GB | |
| Example output: | |
| C:\BasePath\Subfolder1 | |
| 12,34 GB txt | |
| 5,67 GB doc | |
| C:\BasePath\Subfolder2 | |
| 123,45 GB img | |
| 67,89 GB iso | |
| .PARAMETER Path | |
| Specifies the path whose subfolders are to be examined. | |
| .PARAMETER IgnoreTotalsBelow | |
| Specifies the amount of used space below which a result | |
| for a file type is ignored. Optional, defaults to 500MB. | |
| #> | |
| [CmdletBinding( | |
| PositionalBinding=$True | |
| )] | |
| Param | |
| ( | |
| [Parameter( | |
| Position=0, | |
| HelpMessage="Enter a folder to show subfolder sizes per file type" | |
| )] | |
| [string]$Path, | |
| [Parameter( | |
| Position=1, | |
| HelpMessage="Minimum totals of used space to be listed" | |
| )] | |
| [string]$IgnoreTotalsBelow = "500MB" | |
| ) | |
| Begin{} | |
| Process{ | |
| if (!$Path) { | |
| Write-Host "No path specified!" | |
| Exit | |
| } | |
| foreach ($folder in Get-ChildItem -LiteralPath $Path -Directory) | |
| { | |
| Write-Host "$Path$folder" | |
| gci -Path $Path$folder -File | | |
| group Extension | | |
| select @{n='Extension'; e='Name'}, @{n='TotalSize'; e={$_.Group|measure -Sum Length|% sum }} | | |
| Where-Object {$_.TotalSize -gt $IgnoreTotalsBelow} | | |
| Sort-Object -Descending -Property TotalSize | | |
| foreach {" {0,6:N2} GB" -f ($_.TotalSize/1GB) + " " + $_.Extension.Substring(1)} | |
| } | |
| } | |
| End{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment