> 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/es/comandos-de-powershell/new-udtreeview.md).

# New-UDTreeView

### Sinopsis

Crea una nueva vista de árbol.

### Sintaxis

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

### Descripción

Crea una nueva vista de árbol.

### Parámetros

#### -Id

El ID del componente. Por defecto es un GUID aleatorio.

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

#### -Node

Una colección de nodos raíz para mostrar dentro de la vista de árbol.

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

#### -OnNodeClicked

Un bloque de script que se llama cuando se hace clic en un nodo. $EventData contendrá el nodo en el que se hizo clic.

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

#### -Style

Un conjunto de estilos CSS que se aplican a la vista de árbol.

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

#### -ClassName

Un className CSS que se aplica a la vista de árbol.

```
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).
```

### Salidas

\-------------------------- EJEMPLO 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/es/comandos-de-powershell/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.
