Sophisticated Directory Filtering in PowerShell v3

by Aug 24, 2012

In PowerShell v3, Get-ChildItem now supports sophisticated filtering through its –Attribute parameter. To get all files in your Windows folder or one of its subfolders that are not system files but are encrypted or compressed, use something like this:

Get-ChildItem $env:windir -Attributes !Directory+!System+Encrypted,!Directory+!System+Compressed -Recurse -ErrorAction SilentlyContinue


Note how "!" negates the filter.

The -Attributes parameter supports these attributes: Archive, Compressed, Device, Directory, Encrypted, Hidden, Normal, NotContentIndexed, Offline, ReadOnly, ReparsePoint, SparseFile, System, and Temporary.

Twitter This Tip! ReTweet this Tip!