> 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/it/comandi-powershell/new-udtreeview.md).

# New-UDTreeView

New-UDTreeView crea un albero gerarchico di elementi New-UDTreeNode espandibili in PowerShell Universal per esplorare strutture di dati annidate.

### Sinossi

Crea una nuova vista ad albero.

### Sintassi

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

### Descrizione

Crea una nuova vista ad albero.

### Parametri

#### -Id

L'ID del componente. Per impostazione predefinita è un GUID casuale.

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

#### -Node

Una raccolta di nodi radice da mostrare all'interno della vista ad albero.

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

#### -OnNodeClicked

Un blocco di script che viene chiamato quando si fa clic su un nodo. $EventData conterrà il nodo su cui si è fatto clic.

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

#### -Style

Un insieme di stili CSS da applicare alla vista ad albero.

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

#### -ClassName

Un className CSS da applicare alla vista ad albero.

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

#### -Expanded

Indica se la vista ad albero deve essere espansa per impostazione predefinita.

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

#### -PreventCollapse

Impedisce che la vista ad albero si comprima quando si fa clic su un nodo. Presuppone -Expanded.

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

#### Parametri comuni

Questo cmdlet supporta i parametri comuni: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable e OutVariable. Per maggiori informazioni, veda [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

### Output

### Esempi

#### Esempio 1: vista ad albero

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

Un componente di base per la vista ad albero.

#### Esempio 2: OnNodeClicked

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

Una vista ad albero con un blocco di script OnNodeClicked che mostra un toast quando si fa clic su un nodo.

#### Esempio 3: Expanded

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

Una vista ad albero espansa per impostazione predefinita.

#### Esempio 4: OnNodeClicked

```powershell
New-UDTreeView -Node {
    New-UDTreeNode -Name "Root Node" -Id "root4"
} -Id "treeview4" -OnNodeClicked {
    New-UDTreeNode -Name "Child Node"
}
```

Una vista ad albero con un blocco di script OnNodeClicked che aggiunge un nodo figlio quando si fa clic su un nodo.

#### Esempio 5: icone

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

Una vista ad albero con icone per i nodi.

#### Esempio 6: PreventCollapse

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

Una vista ad albero espansa per impostazione predefinita che impedisce la compressione quando si fa clic su un nodo.


---

# 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/it/comandi-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.
