PowerTip: List all subfolders under a target path with PowerShell


Summary: Use Get-Childitem to provide a printable list of all folders under a path.

Hey, Scripting Guy! Question I used to use tree.com to get a list of folders on a computer. Is there something close to that in PowerShell? Maybe something I could print?

Hey, Scripting Guy! Answer If you were to use Get-Childitem combined with Select-Object, you could get a pretty clean list. Here’s an example that targets drive c: and all hidden folders. It displays only directories and their full paths.

Get-ChildItem -Path C:\ -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName

The Doctor

Comments (2)

  1. Panzerbjørn says:

    Ahhh… So sad:
    Get-ChildItem : A parameter cannot be found that matches parameter name ‘Directory’.

    I guess this command doesn’t work on PS version 2… :-/

  2. @Panzerbjørn

    You are correct, this feature to choose Directory or File I believe was implemented in Version 3.0

    Cheers
    Sean
    Honorary Scripting Guy

Skip to main content