New-ConsoleTree
Creates a console tree from nested Label/Children records calls, hierarchical objects or nested hashtables.
Syntax
New-ConsoleTree
[[-Content] <ScriptBlock>]
[-NoRoot]
[-Presentation <PresentationOptions>]
[[-Title] <Object>]
[-WrapLabels]
[<CommonParameters>]#NodesNew-ConsoleTree
[-Children <ScriptBlock>]
[-ChildrenProperty <String>]
[-Depth <Int32>]
[-DetailProperty <String>]
-InputObject <PSObject>
[-LabelProperty <String>]
[-MaxItems <Int32>]
[-MaxNodes <Int32>]
[-NoRoot]
[-Presentation <PresentationOptions>]
[-StatusProperty <String>]
[[-Title] <Object>]
[-WrapLabels]
[<CommonParameters>]#ObjectsDescription
Three ways in, one tree out. Nodes: a script block of Label/Children records calls, each with its own status, detail and children (strings become leaves shown literally); nodes can also be piped in. Objects: pipe hierarchical objects (groups and members, folders and files) and name their children with -ChildrenProperty or a -Children script block ($_ is the parent); -LabelProperty, -StatusProperty and -DetailProperty pick what each node shows, and -Depth, -MaxItems and -MaxNodes keep a large or cyclic hierarchy bounded and mark what was left out (a repeated item is shown once with "(cycle)"). Hashtables: -InputObject maps keys to nested hashtables (child nodes), arrays (leaves) or other values (a muted note); use [ordered] to keep order. The title (markup allowed) is the root; without it the top-level nodes are the roots.
Examples
Example 1
$treeOptions = @{
Title = '[bold]evotec.xyz[/]'
Content = {
[pscustomobject]@{ Label = 'MX'; Status = 'Pass'; Detail = '2 records'; Children = @(& {
[pscustomobject]@{ Label = 'evotec-xyz.mail.protection.outlook.com'; Detail = 'priority 0' }
}) }
[pscustomobject]@{ Label = 'SPF'; Status = 'Warn'; Detail = '9 of 10 DNS lookups'; Children = @(& {
'include:spf.protection.outlook.com'
'include:_spf.salesforce.com'
}) }
[pscustomobject]@{ Label = 'DMARC'; Status = 'Fail'; Detail = 'p=none' }
}
}
New-ConsoleTree @treeOptions | Show-ConsoleA mail domain with records and their state
Example 2
$treeOptions = @{
Children = { if ($_.PSIsContainer) { Get-ChildItem $_.FullName } }
Depth = 3
}
Get-Item . | New-ConsoleTree @treeOptions | Show-ConsoleFolders and files from the pipeline, three levels deep
Example 3
$groups = @(
[pscustomobject] @{ Name = 'Domain Admins'; Health = 'Warn'; Note = '6 members'; Members = @(
[pscustomobject] @{ Name = 'Tier 0 operators'; Health = 'Pass'; Members = @([pscustomobject] @{ Name = 'anna.k' }) }
[pscustomobject] @{ Name = 'svc-backup'; Health = 'Fail'; Note = 'password never expires' }
) }
)
$treeOptions = @{
Title = 'Privileged groups'
ChildrenProperty = 'Members'
StatusProperty = 'Health'
DetailProperty = 'Note'
}
$groups | New-ConsoleTree @treeOptions | Show-ConsoleHierarchical objects with a status per node
Example 4
$treeOptions = @{
Title = 'evotec.xyz'
InputObject = ([ordered] @{ NS = @('dana.ns.cloudflare.com', 'kirk.ns.cloudflare.com'); MX = [ordered] @{ 'mail.protection.outlook.com' = '52.101.68.17' } })
}
New-ConsoleTree @treeOptions | Show-ConsoleA DNS delegation from nested hashtables
Example 5
Get-ConsoleDemo -Slug 'disk-usage' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'query' | Select-Object -ExpandProperty SourceRead any of these gallery scripts to see New-ConsoleTree in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.
Parameters
- -Content ScriptBlock
- A script block that emits the nodes: Label/Children records calls, or strings for leaves (shown literally).
- -NoRoot SwitchParameter
- Hides the default-on root when a title was supplied.
- -Presentation PresentationOptions
- Typed culture, time-zone and value presentation configuration.
- -Title Object
- The root label (markup allowed; rich text from New-ConsoleText keeps its colours). Without it the top-level nodes are the roots.
- -WrapLabels SwitchParameter
- Wraps node labels and values with hanging indentation.
- -Children ScriptBlock
- A script block that returns an object's children; $_ is the object. Use it when children have to be looked up (Get-ChildItem, Get-ADGroupMember).
- -ChildrenProperty String
- The property that holds an object's children (for example Members or Children).
- -Depth Int32
- Levels of children to follow: New-ConsoleTree defaults to 5. Show-Console -View Tree defaults to 3 for object graphs, or one for wide .NET objects when Depth is omitted.
- -DetailProperty String
- The property shown as a muted note after the label.
- -InputObject PSObject
- Hierarchical objects (pipeline input); each becomes a top-level node. Nodes from Label/Children records go in as they are.
- -LabelProperty String
- The property shown as the node label (default: the object's name, as tables title a record: Name, DisplayName, Title...).
- -MaxItems Int32
- The most children listed per node, and objects listed at the top, before "+N more" (default 25; 0 lists all).
- -MaxNodes Int32
- The most nodes the tree may grow to (default 5000; 0 for no limit); beyond it a "node limit reached" note ends the walk.
- -StatusProperty String
- The property whose value is the node status (pass, fail, warn, skip... or PowerShell's words).
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.