Script output Widget in App or Portal

Product: PowerShell Universal
Version: 5.5

Any tips or tricks on displaying script output in an App or in a Widget on the portal? Ideally what I’m looking for is something like the script output on the Job page (Timestamp, color coding, etc.). This is what I’m using right now but isn’t not as nice as the Job page (notably control characters don’t get rendered correctly)

$JobOutput = (((Get-PSUJobOutput -Job $Job -AsObject) | %{ "[{0}] {1}" -f $_.TimeStamp, $_.Message }) -join [Environment]::NewLine)
New-UDCodeEditor -RenderControlCharacters -ReadOnly -Height '500' -Language 'powershell' -Code $JobOutput -Id 'editor' -Theme 'vs-dark'

I don’t have an answer for you, but am also interested in what you find out for this. I have an interest in displaying this information in this fashion.

I have an app with cards for different things. I have an input that passes over to a script and returns the output. It’s a basic lookup script, in this case for zoom. The important bit is in the # Get the output section and then also in how you actually output your data from the script.

app card:

New-UDApp -Title "Portal Test" -Content {
    New-UDGrid -Container -Spacing 2 -Content {
        $getZoomHeader = New-UDCardHeader -Title 'Get Zoom User' -SubHeader 'Look up a users Zoom info' -Sx @{ backgroundColor = "#1976d2"; color = "white" }
        $getZoomBody = New-UDCardBody -Content {
            New-UDTextbox -Id "zoomUPN" -Label "User Principal Name (username@domain)" -FullWidth
            New-UDButton -Id "zoomButton" -Text "Get Zoom Info" -OnClick {
                $zoomUPN = Get-UDElement -Id "zoomUPN"
                            
                if (-not $zoomUPN.Value) {
                    Show-UDToast -Message "User Principal Name is required" -Duration 3000 -Position "topRight" -MessageColor "red"
                    return
                }
                            
                try {
                    # Show initial toast
                    Show-UDToast -Message "Fetching Zoom info for $($zoomUPN.Value)" -Duration 3000 -Position "topRight" -MessageColor "blue"
                    Set-UDElement -Id "zoomButton" -Attributes @{
                        Icon = (New-UDIcon -Icon 'spinner' -Spin)
                    }
                        
                    # Hide output initially
                    Set-UDElement -Id "zoomOutput" -Properties @{
                        Style = @{display = "none" }
                    }
                                
                    # Get the script reference
                    $Script = Get-PSUScript -Name 'Cloud\Get-ZoomUser.ps1' -TrustCertificate
                    if (-not $Script) {
                        throw "Could not find Get-ZoomUser.ps1 script"
                    }
                                
                    # Invoke the script and get the job
                    $Job = Invoke-PSUScript -Script $Script -UPN $zoomUPN.Value
                                
                    if ($Job) {
                        # Wait for the job to complete
                        $Job | Wait-PSUJob
                                    
                        # Get the output
                        $output = Get-PSUJobOutput -Job $Job
                                    
                        if ($output) {                            
                            # Show and update the output element
                            Set-UDElement -Id "zoomOutput" -Properties @{
                                # Text  = $formattedOutput
                                Text  = $output
                                Style = @{display = "block"; padding = "15px"; whiteSpace = "pre" }
                            }
                                                                        
                            # Show success message
                            Show-UDToast -Message "Immutable ID retrieved successfully" -Duration 3000 -Position "topRight" -MessageColor "green"
                            Set-UDElement -Id "zoomButton" -Attributes @{
                                Icon = (New-UDIcon -Icon 'circle-check' -Color 'green')
                            }
    
                            Start-Sleep -Seconds 3
    
                            #Remove Icon
                            Set-UDElement -Id "zoomButton" -Attributes @{
                                Icon = $null
                            }
                        }
                        else {
                            Show-UDToast -Message "No output received from the script" -Duration 3000 -Position "topRight" -MessageColor "red"
                        }
                    }
                    else {
                        Show-UDToast -Message "Failed to create job" -Duration 3000 -Position "topRight" -MessageColor "red"
                    }
                }
                catch {
                    Show-UDToast -Message "Error: $($_.Exception.Message)" -Duration 5000 -Position "topRight" -MessageColor "red"
                    Set-UDElement -Id "zoomOutput" -Properties @{
                        Text  = "Error: $($_.Exception.Message)"
                        Style = @{display = "block"; padding = "15px"; whiteSpace = "pre" }
                    }
                }
            } -Style $ButtonStyle
            New-UDTypography -Text "Output:" -Variant h6
            New-UDTypography -Id "zoomOutput" -Text "" -Style @{display = "none"; whiteSpace = "pre" }
        }
    
        New-UDCard -Header $getZoomHeader -Body $getZoomBody
    }
}

script output:

Write-Output "======== ZOOM USER DETAILS ========"
            Write-Output "`nZoom ID      : $($z.id)"
            Write-Output "`nDisplay Name : $($z.display_name)"
            Write-Output "`nFirst Name   : $($z.first_name)"
            Write-Output "`nLast Name    : $($z.last_name)"
            Write-Output "`nAgency       : $($z.dept)"
            Write-Output "`nEmail        : $($z.email)"
            Write-Output "`nPhone #      : $($z.phone_number)"
            Write-Output "`nStatus       : $($z.status)"

            $licenseType = switch($z.type) {
                1 { "Basic License" }
                2 { "Full License" }
                3 { "On-Prem" }
                99 { "None" }
                default { "Unknown" }
            }
            Write-Output "`nLicense Type : $licenseType"
            Write-Output "`n================================`n"