Running script on click

Final look of the completed, working script. Once the “Apply Update” button is clicked on the dashboard, the “C:\Temp\Script1.ps1” file is executed and displayed within the code editor located on the dashboard.

$Pages = @()

$Pages += New-UDPage -Name 'CitrixVMs' -Content `
{
    $Columns = @(
                    New-UDTableColumn -Property Server           -Title Server
                    New-UDTableColumn -Property MasterVM         -Title MasterVM
                    New-UDTableColumn -Property Snapshot         -Title Snapshot
                    New-UDTableColumn -Property LastModifiedDate -Title LastModifiedDate
                    New-UDTableColumn -Property Site             -Title Site -Render `
                    {
                        New-UDButton -id "btn$($EventData.Site)" -Text "Apply Update" -OnClick {
                                                                                                    Show-UDToast -Message "Updating $($EventData.Site) master image"
                                                                                                    $Script = "C:\Temp\Script1.ps1"
                                                                                                    $Job = Invoke-UAScript -Script $Script2 -Server "$EventData.Server" | Tee-Object -Variable Job

                                                                                                    IF ($Job.Status -eq 'Failed')
                                                                                                    {
                                                                                                        Start-Sleep -Seconds 1
                                                                                                        $Output = (Get-UAJob -Id $Job.Id).StatusDescription -join ([Environment]::NewLine)
                                                                                                        Set-UDElement -Id 'codeEditor' -Properties @{
                                                                                                                                                        code = $Output
                                                                                                                                                    }

                                                                                                        $Job = Get-UAJob -Id $Job.Id
                                                                                                    }

                                                                                                    ELSE
                                                                                                    {
                                                                                                        While ($Job.Status -ne 'Completed')
                                                                                                        {
                                                                                                            Start-Sleep -Seconds 1
                                                                                                            $Output = (Get-UAJob -Id $Job.Id).StatusDescription -join ([Environment]::NewLine)
                                                                                                            Set-UDElement -Id 'codeEditor' -Properties @{
                                                                                                                                                            code = $Output
                                                                                                                                                        }

                                                                                                            $Job = Get-UAJob -Id $Job.Id
                                                                                                        }

                                                                                                    }
                                                                                                     
                                                                                               }
                    }
                )

    New-UDTable -Data $AllData -Columns

    New-UDCodeEditor -Id 'codeEditor' -Theme 'vs-dark' -Height 600 -Language 'powershell' -ReadOnly
}


New-UDDashboard -Title 'CitrixVMs' -Pages $Pages