Skip to content

Instantly share code, notes, and snippets.

@mortenya
Created November 17, 2015 00:57
Show Gist options
  • Save mortenya/6ef4f223e25819f97dc2 to your computer and use it in GitHub Desktop.
Save mortenya/6ef4f223e25819f97dc2 to your computer and use it in GitHub Desktop.
This little script crawls a file share and adds the file size for GroupWise Archives. I split the name out from the path, but that's unique to my environment. The last bit converts the number to a readable format, and groups duplicate entries.
$tSize = 0
Get-ChildItem -Path \\personal\users\ -Directory -Filter "of*arc" -Exclude '* *' -Recurse | % {
$pSize = 0
Get-ChildItem $_.FullName -File -Recurse | % {
$pSize += $_.Length
$tSize += $_.Length
}
$pProps = New-Object psobject -Property @{
'user'=$(($_.FullName -split '\\')[4]);
'size'=$($pSize)
}
$pProps | select user,size | Export-Csv -Append -NoTypeInformation -Path C:\PSResults\groupwise-arch.csv
}
$tProps = New-Object psobject -Property @{
'user'="total";
'size'=$tSize
}
$tProps | select user,size | Export-Csv -Append -NoTypeInformation -Path C:\PSResults\groupwise-arch.csv
function Format-HumanReadable
{
param ($size)
switch ($size)
{
{$_ -ge 1PB}{"{0:#.###'P'}" -f ($size / 1PB); break}
{$_ -ge 1TB}{"{0:#.###'T'}" -f ($size / 1TB); break}
{$_ -ge 1GB}{"{0:#.###'G'}" -f ($size / 1GB); break}
{$_ -ge 1MB}{"{0:#.##'M'}" -f ($size / 1MB); break}
{$_ -ge 1KB}{"{0:##'K'}" -f ($size / 1KB); break}
default {"{0}" -f ($size) + "B"}
}
}
$csv = Import-Csv C:\PSResults\groupwise-arch.csv | Group-Object -Property user
[array]$newCsv += foreach ($i in $csv) { $i.Group | select -Unique user,@{n='size';e={(($i.group) | measure -Property size -Sum).sum}} }
$newCsv | % { $_.size = Format-HumanReadable($_.size) }
$newCsv | Export-Csv -NoTypeInformation -Path C:\PSResults\groupwise-arch-totals.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment