Interaction features of Universal Dashboard
Universal Dashboard enables the ability to create interactive websites with PowerShell. There are several cmdlets that have been implemented to provide feedback to the user, update components and read the state of components.
You can set string data into the user's clipboard with Set-UDClipboard
.
You can start a download within the user's browser by using Start-UDDownload
. Due to security of web browsers, the user will need to take an action (like click a button) to allow the download to take place. Start-UDDownload
is not suited for large file downloads.
Many components support event handlers in the form of script blocks. You may also see these referred to as endpoints as that is what they were called in Universal Dashboard v2. These event handlers allow you to invoke PowerShell scripts when certain actions take place on the page.
For example, you may have a button click that calls an event handler. This button will show a toast when clicked. You can include any valid PowerShell cmdlet within the event handler code.
Variables are automatically scoped into event handlers. You will be able to access variables that you define outside of the variable within the event handler.
Some event handlers handlers will provide data as a string or as a hashtable. This depends on the event handler you are using. For example, the New-UDButton
-OnClick
event handler does not provide any data. On the other hand, the New-UDSelect
-OnChange
will provider event data.
You can access the event data by using the $Body
variable to access the data as a string (sometimes formatted as JSON) or as a hashtable by using the $EventData
variable.
You can force a form to submit using the Invoke-UDForm
cmdlet. You can optionally chose to enforce validation by including the -Validate
parameter.
You can force a form to validate by using Test-UDForm
.
You can invoke JavaScript from PowerShell by using the Invoke-UDJavaScript
cmdlet.
You can use the Show-UDToast
cmdlet to create a toast message that will appear on the end user's webpage. It happens over a websocket and will show the toast immediately as it is called.
Toasts support icons as strings. You can use all the FontAwesome v5 icons.
Hides a toast based on the specified ID.
You can redirect users to different pages using the Invoke-UDRedirect
cmdlet. It happens over a websocket and will redirect as soon as the cmdlet is called.
Invoke-UDRedirect
will automatically redirect to pages in the dashboard when using a relative path.
If you'd like to redirect to a local path outside of the dashboard, you can use the -Native
parameter.
You can open a modal using the Show-UDModal
cmdlet. It will open as soon as you call it. You can include whatever components you like within the modal.
Read more about Modals here.
You can manage component state dynamically by using the UDElement commands.
You can receive the state of an element using Get-UDElement
. The state will be returned as a hashtable. This is primarily useful for input components.
Alternatively, you can set component state using Set-UDElement
. You will need to specify an ID and a hashtable of properties to set on the component. All built in components support Set-UDElement.
You can remove components from the page using Remove-UDElement
. The component will no longer appear on the page.
Add a child component to an existing parent component.
You can remove all the children components from an component by using Clear-UDElement
.
Some components support reloading. You can trigger a reload of a component using Sync-UDElement
.
You can select a component with Select-UDElement
.
Dashboards integrate directly with the PowerShell host to provide features based on standard cmdlets.
Using the Read-Host
cmdlet will cause a dialog to show on the user's dashboard. The text entered will be returned by the cmdlet.
Using Get-Credential
will cause a dialog to show that accepts a username and password. A PSCredential
object will be returned from the cmdlet.
Cmdlets that use the progress stream or the use of the Write-Progress
cmdlet will result in a progress dialog being shown. The popup will show the activity, percent completed and current operation.
You can disable the Write-Progress integration by setting the $ProgressPreference
to SilentlyContinue
.
You can use the $Host.UI.PromptForChoice
function to display a multi-select dialog.