If you ever wanted to send a broadcast to all pages

Product: PowerShell Universal
Version: 5.5.1

pretty basic, and does not work for multi-node env, but a least informs all users about whatever maintenance if needed


$page:broadcast=@{
    set=$true
    active=$false
    message="Broadcast testing - please ignore !"
    duration=10
}

New-UDDynamic -Content {
    while ($page:broadcast.set) {
        if ($page:broadcast.active) {
            Hide-UDToast -id "broadcast"
            Show-UDToast -id "broadcast" -Message $page:broadcast.message -Duration ($page:broadcast.duration * 1000) -BackgroundColor deeppink -Icon bullhorn -IconColor Darkorchid -ReplaceToast -Position topCenter -HideCloseButton -Balloon -MessageColor floralwhite -Broadcast
            foreach($loop in (($page:broadcast.duration-1)..0))  {
                if ($page:broadcast.active) {
                    Set-UDElement -id "tick" -Properties @{value=$loop}
                    Start-Sleep 1
                } else {
                    break
                }
            }
        }
        else {
            Hide-UDToast -id "broadcast"
            Set-UDElement -id "tick" -Properties @{value=""}
            Start-Sleep 0.1 
        }
    }
}

New-UDGrid -Container -spacing 10 -Content {
    New-UDGrid -Item -ExtraSmallSize 12 -Content {
        New-UDTextbox -id "desc"  -value "Display a broadcast message on all pages"  -FullWidth -Multiline -Disabled -Variant outlined
    }

    New-UDGrid -Item -ExtraSmallSize 8 -Content {
        New-UDTextbox -id "message" -label "message text to broadcast" -value $page:broadcast.message -FullWidth  -Variant filled -OnChange {
            $page:broadcast.message=$eventdata
        }
    }

    New-UDGrid  -Item -ExtraSmallSize 2 -Content {
        New-UDSwitch -Id "onoff" -Label "Broadcast off/on" -Color secondary -OnChange {
            $page:broadcast.active = $eventdata
        }
    }

    New-UDGrid -Item -ExtraSmallSize 2 -Content {
        New-UDTextbox -id "tick" -label "refresh in" -value "0" -FullWidth  -Disabled -Variant outlined
    }
}

I like this.

You could probably set parameters as cache items which would allow multinode if servers are git synced or using SQL database.

Set-PSUCache -Key BroadcastStatus -Value $True -AbsoluteExpiration (Get-Date).AddHours(1) -Persist
Set-PSUCache -Key BroadcastMessage -Value 'Upgrade in progress. Expect disruption for 1  hour'

$page:broadcast=@{
    set=$true
    active= Get-PSUCache -Key BroadcastStatus
    message= Get-PSUCache -Key BroadcastMessage
    duration=10
}

Thanks.
I do not have multi-node and can’t test.
But I guess the limitation is the show-udtoast cmdlet. The -broadcast option does not affect multi-node.

Ah, i got you.

I quickly skimmed the code and thought it was presenting an additional page, like a header.

You’re right. Broadcast method wouldn’t work, but I think implementing a dynamic element with autorefresh at the top of each dashboard that shows only when cache item is set might be a workaround.