Grouping Files Based On Size

by Jun 8, 2011

In a previous tip, we showed you how to group using your own criteria. Group-Object can also auto-create hash tables so that you can easily create groups of objects of a kind. Here is an example:

$criteria = {
    if ($_.Length -lt 1KB) {
    } elseif ($_.length -lt 1MB) {    
    } else { 
        'huge' }

$myFiles = dir $env:windir | Group-Object -Property $criteria -asHash -asString

# list only huge files:

# list only small files:


Twitter This Tip!
ReTweet this Tip!