How to list directories a certain level deep using the Tree command in PowerShell?
Solution 1:
Tree is not a PowerShell cmdlet, as we know, and as such cannot be used in the vein you are trying to do.
For what you are after, you have to write this yourself or look for something already done.
You cannot filter external .exe(s) as you can with say Get-ChildItem, and such, without capturing all its output as an object then, using the normal object walking efforts available.
If you search for such solutions, you'd come across these examples:
PowerTip: Limit Get-Childitem to a limited depth in the tree
Get-Childitem C:\Users\CurlyBlue -include *.docx -depth 2
PowerTip: View Directory List as Tree by Using PowerShell
Show-Tree e:\data –depth 2
Powershell Directory Tree
get-childitem -Path Q:\ -Recurse -Directory -Depth 3|select FullName|export-csv C:\file-tree.csv
# or this way
(get-childitem -Path d:\projects -Recurse -Directory -Depth 2).FullName
There are a number of other options to dig at this as well. All searchable on the web.
For example: See also
List contents of directories in a tree-like format with colorization and lots of options