Recently I had to do a pretty common task on a cluttered file server, find out how many files are older than “%” and how much disk space are they taking up? I found a number of different methods, each more elaborate than the last. Finally I devised one that is simple, efficient and the best part, a one-liner:
get-childitem -recurse | where-object {$_.lastwritetime -lt “12/31/2004”} | Measure-Object length -sum
It will return something that looks like this:
Count : 21798 Average : Sum : 7610009508 Maximum : Minimum : Property : Length
If you’re not totally familiar with PowerShell’s syntax (as I wasn’t), the “-lt” is the PS equivelant of “<“, so you guessed it, instead of “>” you would use “-gt”. Oddly, if you try and use < or > PS errors out but informs you that the symbols “are not supported yet”
If you want to pull other data properties from your files, but don’t want to guess the syntax, run this command on a directory containing files and folders:
get-childitem | get-Member -Membertype property
And it will list other properties you may be interested in.