PowerTip: Display Hidden Files in PowerShell


Summary: Boe Prox shows how to use Windows PowerShell to display hidden files.

Hey, Scripting Guy! Question How can I use Windows PowerShell to display hidden files and folders?

Hey, Scripting Guy! AnswerThere are a couple of approaches that use Get-ChildItem:

      • Get-ChildItem –Hidden
      • Get-ChildItem –Attributes H

Comments (3)

  1. mlebel says:

    It’s strange that the TechNet page for Get-ChildItem does not show anything about the parameters -Hidden nor -Attributes as of 2015-12-28 (page was updated on 2015-08-09). However, the article does mention about list mode : "The valid values for mode are
    d (directory), a (archive), r (read-only), h (hidden), and s (system)"

    The attributes property is of type IO.FileAttributes and is enumerable with the following values:

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

    But not supported by the -Attributes parameter.

    While trying to display only an encrypted file on my desktop, the first 3 statements failed to show me the desired results but the last one worked :
    GCI -Fo | ? Attributes -contains "Encrypted" | Fl Name, Attributes
    GCI -Fo | ? Attributes -eq "Encrypted" | Fl Name, Attributes
    GCI -Fo | ? Attributes -in "Encrypted" | Fl Name, Attributes
    GCI -Fo | ? Attributes -like "*Encrypted*" | Fl Name, Attributes
    Name : Sunday 27 December 2015 – 10.51.43 PM.png
    Attributes : ReadOnly, Hidden, Archive, Encrypted

  2. mlebel says:

    Also, the approaches demonstrated in this article will only display the hidden files, not all the files plus/including the hidden ones.

    To get hidden items and non hidden items mixed together, use the -Force parameter.

  3. spacenomyous says:

    When did the -hidden switch get added to GCI? I can’t find the parameter in the help files and it’s easy to reproduce if you open a powershell -v 2 and do a gci -hidden it fails.

Skip to main content