Repository navigation
Does Get-Process support rendering processes as a tree-table?
#25294
Replies: 4 comments 5 replies
|
Not built in, but PowerShell 7 adds a function Show-ProcessTree {
param([int]$RootId = 0)
$procs = Get-Process
$byId = @{}; foreach ($p in $procs) { $byId[$p.Id] = $p }
$children = @{}
foreach ($p in $procs) {
$parentId = if ($p.Parent -and $byId.ContainsKey($p.Parent.Id)) { $p.Parent.Id } else { 0 }
if (-not $children.ContainsKey($parentId)) { $children[$parentId] = [System.Collections.Generic.List[object]]::new() }
$children[$parentId].Add($p)
}
function Write-Node($id, $indent) {
foreach ($c in ($children[$id] | Sort-Object ProcessName)) {
'{0}{1} ({2})' -f $indent, $c.ProcessName, $c.Id
if ($children.ContainsKey($c.Id)) { Write-Node $c.Id ($indent + ' ') }
}
}
Write-Node $RootId ''
}
Show-ProcessTree # whole tree
Show-ProcessTree -RootId (Get-Process -Id $PID).Parent.Id # just one branchSample output (PowerShell 7.4.6 on Ubuntu 24.04): Processes whose parent has already exited (or isn't visible to you) are shown at the top level, which is also how |
|
Nothing built in, but you can create a function (like the nice example from Marcus de Paula (@marcuspaula-seceng)). You can also try the Install-PSResource -Name 'Microsoft.PowerShell.ConsoleGuiTools'
Get-Process | Show-ObjectTree
Get-Process -Name 'msedge' | Show-ObjectTree
|
|
Mr Beedell, Roke Julian Lockhart (@beedell-roke) - this has been in discussion in the Cmdlets Working Group where I have been looking at adding a Parent Parameter to Get-Process. & I've even debated whether or not a [-Children] parameter is needed too. That is needed as a first step before we could look at returning a full Process Tree, which we've been debating about how this should be, like is it a default view that we display when you run I'd like an end goal to be similar to what is shown by Marcus de Paula (@marcuspaula-seceng) using that property except that we'd continue to return the objects with the properties that are shown today & crucially still allow people to make use of the pipeline. Please add examples of how you'd like this to work into that linked issue & importantly any suggestions on how it should display too so that we can consider it, but yes this is something that I'd like to have be part of the Get-Process cmdlet. There is a Module on the Gallery that implements a Get-ProcessTree function but it doesn't meet my strict needs or potential desired output here. |
|
My view is thst |



Ryan Yates (@kilasuit), (and Sam Erde (@SamErde)), I filed
issues/24471some years ago, requesting exactly that.