Skip to content

Instantly share code, notes, and snippets.

@MHanafy
Last active Jul 22, 2021
Embed
What would you like to do?
#Get sizes for the latest version of all files
$data = p4 sizes //huxley/branches/dev/huxley.net_phase2/...
#Use regex to parse the data and extract file extension and size
$regex = [regex]::new('.*\/.*?(?:(.*?)\.?([^.]*?))#\d*\s(\d*)\sbytes', [Text.RegularExpressions.RegexOptions]::Compiled)
#prepare, aggregate and format the data
$data.Split([Environment]::NewLine) | %{$regex.matches($_)} |
%{[PSCustomObject]@{Ext = if($_.Groups[1].Length -ne 0){$_.Groups[2].Value}else{"[No Ext.]"}; Size=$_.Groups[3].Value} } |
group-object Ext | %{[PSCustomObject]@{Ext=$_.Name; Group=$_.Group | Measure-object Size -Sum -Average -Maximum -Minimum}} |
%{[PSCustomObject]@{Ext=$_.Ext; Count=$_.Group.Count; Sum=$_.Group.Sum; Max=$_.Group.Maximum; Min=$_.Group.Minimum; Avg=$_.Group.Average}} |
Sort-Object -Descending Max | FT Ext, @{Label="Count"; Expression = {$_.Count.ToString("N0")}},
@{Label="Sum (MB)"; Expression = {($_.Sum/1024/1024).ToString("N0")}}, @{Label="Min (MB)"; Expression = {($_.Min/1024/1024).ToString("N0")}},
@{Label="Max (MB)"; Expression = {($_.Max/1024/1024).ToString("N0")}}, @{Label="Avg (MB)"; Expression = {($_.Avg/1024/1024).ToString("N0")}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment