June 28th, 2016

PowerTip: List all subfolders under a target path with PowerShell

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.