Public/Get-DirectorySize.ps1
<#
# Get-DirectorySize Ohne Beschreibung - **Hashtags** UserCmdlet - **Version** 2020.12.9 #> using namespace System Set-StrictMode -Version Latest function Get-DirectorySize { <# .SYNOPSIS Zeigt den belegt Ordner-Platz an. .PARAMETER Path Der Order ab dem die Ordner-Größen gemessen werden soll. .EXAMPLE Get-DirectorySize -Path $env:USERPROFILE\.vscode\extensions #> param ( [Parameter(Mandatory = $true)] [ValidateScript({ $isExistContainer = Test-Path -Path $_ -PathType Container if(-not $isExistContainer) { throw [System.Exception]::new("The path '$_' does not exist.") } $pathObject = Get-Item -Path $_ if(-not ($pathObject -is [System.Io.DirectoryInfo])) { throw [System.Exception]::new("The path $_ is not a DirectoryInfo object.") } return $true })] [string]$Path ) begin { $totalSum = 0 $BaseDirectories = Get-ChildItem -Path $Path -Directory -ErrorAction Ignore } process { $zähler = 0 $multiplikator = 100/$BaseDirectories.Count $BaseDirectories | ForEach-Object { $lineSum = Get-ChildItem -Path $_.FullName -File -Force -Recurse -ErrorAction Ignore | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum $totalSum += $lineSum [PSCustomObject]@{ Name = $_.Name SizeMB = [Math]::Ceiling($lineSum / 1MB) FullName = $_.FullName } $zähler++ Write-Progress -Activity 'Analyse Directory Size' -Status ("Actual total directory size over {0} is {1:#,##0} GB." -f $Path, [Math]::Round($totalSum / 1GB, 2)) -CurrentOperation "Calculate directory '$($_.Name)'" -PercentComplete ([Math]::Floor($zähler * $multiplikator)) } | Sort-Object -Property SizeMB -Descending } end { Write-Progress -Activity 'Analyse Directory Size' -Completed "Total Directory Size over '{0}' is {1:#,##0} GB." -f $Path, [Math]::Round($totalSum / 1GB, 2) | Write-Warning } } Set-StrictMode -Off |