> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/new-udtreeview.md).

# New-UDTreeView

### Synopsis

Creates a new tree view.

### Syntax

```powershell
New-UDTreeView [[-Id] <String>] [-Node] <ScriptBlock> [[-OnNodeClicked] <Endpoint>] [[-Style] <Hashtable>] [[-ClassName] <String>] [-Expanded] [-PreventCollapse] [<CommonParameters>]
```

### Description

Creates a new tree view.

### Parameters

#### -Id

The ID of the component. It defaults to a random GUID.

```
Required?                    false
Position?                    1
Default value                [Guid]::NewGuid()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Node

A collection of root nodes to show within the tree view.

```
Required?                    true
Position?                    2
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnNodeClicked

A script block that is called when a node is clicked. $EventData will contain the node that was clicked.

```
Required?                    false
Position?                    3
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Style

A set of CSS styles to apply to the tree view.

```
Required?                    false
Position?                    4
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

A CSS className to apply to the tree view.

```
Required?                    false
Position?                    5
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    -Expanded [<SwitchParameter>]
        Whether the tree view should be expanded by default.

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    -PreventCollapse [<SwitchParameter>]
        Prevents the tree view from collapsing when a node is clicked. Assumes -Expanded.

Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
```

### Outputs

\-------------------------- EXAMPLE 1 --------------------------

```
PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root1" -Children {
PS >         New-UDTreeNode -Name "Child Node" -Id "child1" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node" -Id "grandchild1" -Leaf
PS >         }
PS >         New-UDTreeNode -Name "Child Node 2" -Id "child2" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild2" -Leaf
PS >         }
PS >     }
PS > } -Id "treeview1"

Tree View|A basic tree view component.




-------------------------- EXAMPLE 2 --------------------------

PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root2" -Children {
PS >         New-UDTreeNode -Name "Child Node" -Id "child3" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node" -Id "grandchild3" -Leaf
PS >         }
PS >         New-UDTreeNode -Name "Child Node 2" -Id "child4" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild4"
PS >         }
PS >     }
PS > } -Id "treeview2" -OnNodeClicked {
PS >     Show-UDToast -Message "You clicked $($EventData.Id)"
PS > }

OnNodeClicked|A tree view with an OnNodeClicked script block that shows a toast when a node is clicked.




-------------------------- EXAMPLE 3 --------------------------

PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root3" -Children {
PS >         New-UDTreeNode -Name "Child Node" -Id "child5" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node" -Id "grandchild5"  -Leaf
PS >         }
PS >         New-UDTreeNode -Name "Child Node 2" -Id "child6" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild6"  -Leaf
PS >         }
PS >     }
PS > } -Id "treeview3" -Expanded

Expanded|A tree view that is expanded by default.




-------------------------- EXAMPLE 4 --------------------------

PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root4"
PS > } -Id "treeview4" -OnNodeClicked {
PS >     New-UDTreeNode -Name "Child Node"
PS > }

OnNodeClicked|A tree view with an OnNodeClicked script block that adds a child node when a node is clicked.




-------------------------- EXAMPLE 5 --------------------------

PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root5" -Children {
PS >         New-UDTreeNode -Name "Child Node" -Id "child7" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node" -Id "grandchild7" -Leaf -Icon (New-UDIcon -Icon "File")
PS >         } -Icon (New-UDIcon -Icon "Folder") -ExpandedIcon (New-UDIcon -Icon "FolderOpen")
PS >         New-UDTreeNode -Name "Child Node 2" -Id "child8" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild8" -Leaf -Icon (New-UDIcon -Icon "File")
PS >         } -Icon (New-UDIcon -Icon "Folder") -ExpandedIcon (New-UDIcon -Icon "FolderOpen")
PS >     }
PS > } -Id "treeview5" -Expanded

Icons|A tree view with icons for nodes.




-------------------------- EXAMPLE 6 --------------------------

PS >New-UDTreeView -Node {
PS >     New-UDTreeNode -Name "Root Node" -Id "root6" -Children {
PS >         New-UDTreeNode -Name "Child Node" -Id "child9" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node" -Id "grandchild9"  -Leaf
PS >         }
PS >         New-UDTreeNode -Name "Child Node 2" -Id "child10" -Children {
PS >             New-UDTreeNode -Name "Grandchild Node 2" -Id "grandchild10"  -Leaf
PS >         }
PS >     }
PS > } -Id "treeview3" -Expanded -PreventCollapse

PreventCollapse|A tree view that is expanded by default and prevents collapsing when a node is clicked.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-udtreeview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
