Home HowTo FileSystem Searching For File Attributes

Searching For File Attributes

In PowerShell 3.0, Get-ChildItem has a new parameter called Attributes. With it, you can find files and folders based on their attributes.

This is a list of commonly used attributes:

  • Archive
  • Compressed
  • Device
  • Directory
  • Encrypted
  • Hidden
  • Normal
  • NotContentIndexed
  • Offline
  • ReadOnly
  • ReparsePoint
  • SparseFile
  • System
  • Temporary

To find all compressed files in your home folder, try this:

Get-ChildItem -Path $home -Recurse -Attributes !Directory+Compressed
Get-ChildItem -Path $home -Recurse -Attributes !D+C

“!” negates an attribute, so in the previous example, “!D” made sure we only got files, no directories. “+” combines attributes, so only files were found that were also compressed. The parameter supports multiple comma-separated values, so to find both compressed and encrypted files that are no system files, try this:

Get-ChildItem -Path $home -Recurse -Attributes !D+!S+C, !D+!S+E

Using attributes can provide a lot of information. For example, to analyze which file extensions in your home folder are not indexed, check this out:

PS> Get-ChildItem -Path $home -Recurse -Attributes NotContentIndexed+!D |
 Group-Object -Property Extension -NoElement |
 Sort-Object -Property Name

Count Name
----- ----
    2 .1
    1 .2
    1 .dll
    1 .exe...