PowerTip: Use PowerShell to List Only Directories

Summary: Learn how to use Windows PowerShell to show all directories.

Hey, Scripting Guy! Question How can I use Windows PowerShell to list ONLY directories in a folder structure?

Hey, Scripting Guy! Answer Use Get-ChildItem on the target folder and specify the Directory parameter:

Get-ChildItem C:\Foo –recurse -directory

Comments (4)

Cancel reply

  1. Anonymous says:

    i ran it on windows 7 powershell , got following error

    PS C:> Get-ChildItem C:chrome -recurse -directory
    Get-ChildItem : A parameter cannot be found that matches parameter name ‘directory’.
    At line:1 char:44
    + Get-ChildItem C:chrome -recurse -directory <<<<
    + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

  2. Ron says:

    Is this applicable for Powershell 2.0, doesnt seem to work

  3. Cam says:

    Likewise here too. Too bad Sean can’t test this before posting.

  4. Cam says:

    Found in other pages ….
    Note The –Directory, -File, -Attributes, -Hidden, and –System switches were added to Get-ChildItem cmdlet in Windows PowerShell 3.0. These switches are available via the FileSystem provider. For more information, see Use PowerShell to Find Dynamic Parameters.

Skip to main content