In PowerShell, dir
is an alias for the Get-ChildItem
cmdlet.
Use it with the -Recurse
parameter to list child items recursively:
Get-ChildItem -Recurse
If you only want directories, and not files, use the -Directory
switch:
Get-ChildItem -Recurse -Directory
The -Directory
switch is introduced for the file system provider in version 3.0.
For PowerShell 2.0, filter on the PSIsContainer
property:
Get-ChildItem -Recurse |Where-Object {$_.PSIsContainer}
(PowerShell aliases support parameter resolution, so in all examples above, Get-ChildItem
can be replaced with dir
)