Public/Get-DirectorySize.ps1
<#
# Get-DirectorySize Ohne Beschreibung - **Hashtags** UserCmdlet - **Version** 2019.09.09 #> using namespace System using namespace System.Runtime.InteropServices $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop Set-StrictMode -Version Latest function Get-DirectorySize { <# .SYNOPSIS .DESCRIPTION .EXAMPLE Get-DirectorySize -Path $env:USERPROFILE\.vscode\extensions .PARAMETER Path Der Order ab dem die Ordner-Größen gemessen werden soll. .INPUTS .OUTPUTS .NOTES #> 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 { } process { Get-ChildItem -Path $Path -Directory -ErrorAction Ignore | ForEach-Object { $sum = Get-ChildItem -Path $_.FullName -File -Force -Recurse -ErrorAction Ignore | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum [PSCustomObject]@{ Name = $_.Name SizeMB = [int]($sum / 1MB) FullName = $_.FullName } } } end { } } |