Skip to content

Instantly share code, notes, and snippets.

@davidlares
Last active March 31, 2026 18:43
Show Gist options
  • Select an option

  • Save davidlares/44e8d0df9f5d4bd569f174069876362f to your computer and use it in GitHub Desktop.

Select an option

Save davidlares/44e8d0df9f5d4bd569f174069876362f to your computer and use it in GitHub Desktop.
Powershell's version of the tree command (Linux fashion) + Filter included
function Show-Tree {
param(
[string]$Path = ".",
[int]$Indent = 0
)
Get-ChildItem -LiteralPath $Path |
Where-Object { $_.Name -ne "vendor" } |
Sort-Object -Property @{Expression = {$_.PSIsContainer}; Descending = $true}, Name |
ForEach-Object {
$prefix = (" " * $Indent) + "|-- "
Write-Output ($prefix + $_.Name)
if ($_.PSIsContainer) {
Show-Tree -Path $_.FullName -Indent ($Indent + 4)
}
}
}
Show-Tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment