Skip to content

Instantly share code, notes, and snippets.

@taidalog
Last active June 9, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taidalog/860884478b98ff6c66d1635538ba961a to your computer and use it in GitHub Desktop.
Save taidalog/860884478b98ff6c66d1635538ba961a to your computer and use it in GitHub Desktop.
Set-StrictMode -Version Latest
function Measure-Directory {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
Position=0,
ParameterSetName="Path",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Path to one or more locations.")]
[Alias("PSPath")]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path $_ -PathType 'Container'})]
[string[]]
$Path
)
begin {
}
process {
foreach ($p in $Path) {
$convertedPath = Convert-Path $p
Write-Verbose "$($convertedPath)"
$childItems = @(Get-ChildItem -LiteralPath $convertedPath -File)
[long]$totalLength = 0
if ($childItems.Length -gt 0) {
[long]$totalLength = ($childItems | Measure-Object Length -Sum).Sum
}
[PSCustomObject]@{
Length = $totalLength
LengthMB = [Math]::Round($totalLength / 1MB, 2)
LengthGB = [Math]::Round($totalLength / 1GB, 2)
Count = $childItems.Length
FullName = $convertedPath
}
}
}
end {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment