Metrics/FilesByExtension.metric.ps1
<# .SYNOPSIS Gets files by extension .DESCRIPTION Gets the number of files of each extension. .LINK Import-Metric .EXAMPLE dir -File -Recurse | FilesByExtension #> param( [Parameter(ValueFromPipelineByPropertyName)] [string] $Extension ) begin { $ExtensionsFound = [Ordered]@{} } process { $ExtensionsFound[$Extension]++ } end { foreach ($sorted in $ExtensionsFound.GetEnumerator() | Sort-Object Value -Descending) { [PSCustomObject][Ordered]@{ Extension = $sorted.Key Count = $sorted.Value } } } |