For PowerShell 3.0 and greater:
Get-ChildItem -Directory
You can also use the aliases dir
, ls
, and gci
For PowerShell versions less than 3.0:
The FileInfo
object returned by Get-ChildItem
has a "base" property, PSIsContainer
. You want to select only those items.
Get-ChildItem -Recurse | ?{ $_.PSIsContainer }
If you want the raw string names of the directories, you can do
Get-ChildItem -Recurse | ?{ $_.PSIsContainer } | Select-Object FullName
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…