How do I get only directories using Get-ChildItem?

I’m using PowerShell 2.0 and I want to pipe out all the subdirectories of a certain path. The following command outputs all files and directories, but I can’t figure out how to filter out the files.

Get-ChildItem c:\mypath -Recurse

I’ve tried using $_.Attributes to get the attributes but then I don’t know how to construct a literal instance of System.IO.FileAttributes to compare it to. In cmd.exe it would be

dir /b /ad /s

16 Answers
16

Leave a Comment