powershell - Determine recursively both COUNT and SUM of all extensions in a folder -
i able select remote folder , scan recursively file extensions. each extension discovered, need total count , sum individual file types.
i've found script here works single file extension using -include switch, rather running script scores of times, nice run once , collect extensions.
$hostname=hostname $directory = "d:\foo" $folderitems = get-childitem $directory -recurse -include *.txt $measurement = $folderitems | measure-object -property length -sum $colitems = $folderitems | measure-object -property length -sum "$hostname;{0:n2}" -f ($colitems.sum / 1mb) + "mb;" + $measurement.count + " files;"
i think need use get-childitem $directory | group-object -property extension
somehow list extensions, if that's helpful.
the ideal output this:
extension, size (mb), count
jpg,1.72,203
txt,0.23,105
xlsx,156.12,456
i'm using powershell v4.0 on windows 7 machine remotely connect server, run script locally, has v3.0 win 2008 r2 machine.
does have ideas?
this 1 approach:
#get items get-childitem -path $directory -recurse | #get files where-object { !$_.psiscontainer } | #group extension group-object extension | #get data select-object @{n="extension";e={$_.name -replace '^\.'}}, @{n="size (mb)";e={[math]::round((($_.group | measure-object length -sum).sum / 1mb), 2)}}, count extension size (mb) count --------- --------- ----- mkv 164,03 1 xlsx 0,03 3 dll 0,32 5 lnk 0 1 url 0 1 txt 0 1
Comments
Post a Comment