From 346e102027047eb27071d1c8c720d944b14ef1a9 Mon Sep 17 00:00:00 2001 From: BoSen29 <54361737+BoSen29@users.noreply.github.com> Date: Tue, 17 Dec 2019 15:51:10 +0100 Subject: [PATCH] Fixes #1381 (#1388) Adds new param "scheduled" to target scheduled endpoints to invoke. --- src/UniversalDashboard/Controls/src/event.ps1 | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/UniversalDashboard/Controls/src/event.ps1 b/src/UniversalDashboard/Controls/src/event.ps1 index 30b6d1bc..f6e896df 100644 --- a/src/UniversalDashboard/Controls/src/event.ps1 +++ b/src/UniversalDashboard/Controls/src/event.ps1 @@ -8,10 +8,17 @@ function Invoke-UDEvent { [String]$Id, [Parameter( Mandatory = $true, - Position = 1 + Position = 1, + ParameterSetName = "onClick" )] [ValidateSet("onClick")] - [string]$event + [string]$event, + [Parameter( + Mandatory = $true, + Position = 1, + ParameterSetName = "Scheduled" + )] + [switch]$scheduled ) Begin { @@ -19,12 +26,33 @@ function Invoke-UDEvent { } Process { - Invoke-UDJavaScript -javaScript " - document.getElementById('$Id').click(); - " + if ($PSCmdlet.ParameterSetName -eq "onClick") { + Invoke-UDJavaScript -javaScript " + document.getElementById('$Id').click(); + " + } + elseif ($PSCmdlet.ParameterSetName -eq "Scheduled") { + $dashboard = Get-UDDashboard + $endpoint = $dashboard.DashboardService.EndpointService.ScheduledEndpoints | where-object Name -eq $Id + + if ($endpoint) { + try { + $endpoint.ScriptBlock.Invoke() | Out-Null + } + catch { + throw ("Invoking endpoint $Id failed with: $($_.Exception.Message)") + } + + } + else { + Write-UDLog "Attempting to trigger $Id failed, unable to locate endpoint." + } + + } + } End { } -} \ No newline at end of file +}