Creating a Table from a Tree View OnNodeClick Event

I’m trying to create a Table when there is a selection from a TreeView click. The treeview is a list of server names and on click, I take the value and do a sql query to gather some information on the server. I’d like to output this to a new table.

I have the table working outside of the OnNodeClick in the TreeView, so I know it works. It just doesn’t work within the treeview. I’m wondering if it’s a limitation of the OnNodeClick event and if so what my options are.

This is what my current code looks like.

New-UDRow -Columns {

    New-UDColumn -LargeSize 3 -Content {

        New-UDTreeView -Node { New-UDTreeNode -Name "Server Admin" } -OnNodeClick {

            If ($EventData.Name -like 'msn*' -or $EventData.Name -like 'cid*') {

                [string]$sn = $EventData.Name

                #Show-UDToast -Message $EventData.Name -Duration 3000

                New-UDColumn -LargeSize 8 -Contents {

                    $alldisks = Invoke-DbaQuery -SqlInstance $sqlServer -Database $sqlServerDB  -Query "SELECT d.DiskID, d.DiskLetter, d.TotalSpace, d.FreeSpace, d.Monitored, d.AlertThreshold, d.UnitofMeasure FROM ServerCheck_Disks d inner join ServerCheck_Servers s on D.ServerID = s.ServerID where s.ServerName = '$sn'" | ForEach-Object {


                            DiskID         = $_.DiskID

                            DiskLetter     = $_.DiskLetter

                            TotalSpace     = $_.TotalSpace

                            FreeSpace      = $_.FreeSpace

                            Monitored      = $_.Monitored

                            AlertThreshold = $_.AlertThreshold

                            UnitOfMeasure  = $_.UnitOfMeasure



                    New-UDTable -Data $alldisks




            ElseIf ($EventData.Name -eq 'Server Admin') {

                $sAdmins = Get-ServerAdmins

                ForEach ($s in $sAdmins) { 

                    New-UDTreeNode -Name $s



            Else {

                $servers = Get-AssignedServer -ServerAdmin $EventData.Name

                ForEach ($server in $servers) { New-UDTreeNode -Name $server }