Scheduled Dashboard Restart in 2.5.5?

I’ve got multiple complex pages in a dashboard that are split into separate .ps1 files. When I want saved changes to go live in production, I’d like to be able to schedule the restart of that single dashboard.

I’ve been attempting to write a script that will do so, but it’s not recognizing Get-Dashboard nor the -Name parameter on Stop-UDDashboard. Is it still possible to do this in newer versions? All documentation I’ve seen for these appear to be for 1.x.

[error] The term 'Get-UDDashboard' is not recognized as a name of a cmdlet, function, script file, or executable program.
[error] A parameter cannot be found that matches parameter name 'Name'.

Product: PowerShell Universal
Version: 2.5.5

It’s Get-PSUDashboard. Try this:

$Dashboard = Get-PSUDashboard | Where-Object Name -eq 'DashboardName'
$Dashboard | Stop-PSUDashboard
$Dashboard | Start-PSUDashboard
1 Like

OK, so this is the exact code I’ve run:

$HATDashboard = Get-PSUDashboard | Where-Object Name -eq 'HAT_Development'

$HATDashboard 

Write-Output 'Attempting to stop dashboard...'

try {

    $HATDashboard | Stop-PSUDashboard

    Write-Output "Successfully stopped the dashboard!"

}

catch {

    Write-Output "Failed stop dashboard: $($_.Exception.Message)"

} 

Start-Sleep -Seconds 5

Write-Output 'Attempting to restart dashboard...'

try {

    $HATDashboard | Start-PSUDashboard

    Write-Output "Successfully stopped the dashboard!"

}

catch {

    Write-Output "Failed start dashboard: $($_.Exception.Message)"

}

And this is the output:

Dec 15, 2021 10:50 AM [warning] Failed to verify module and server version. Call failed. The SSL connection could not be established, see inner exception. GET https://localhost:443/api/v1/version 
Dec 15, 2021 10:50 AM [warning] Failed to verify module and server version. Call failed. The SSL connection could not be established, see inner exception. GET https://localhost:443/api/v1/version 
Dec 15, 2021 10:50 AM [error] Call failed. The SSL connection could not be established, see inner exception. GET https://localhost:443/api/v1/Dashboard 
Dec 15, 2021 10:50 AM  Attempting to stop dashboard... 
Dec 15, 2021 10:50 AM [error] Cannot bind argument to parameter 'Dashboard' because it is null. 
Dec 15, 2021 10:50 AM  Successfully stopped the dashboard! 
Dec 15, 2021 10:50 AM  Attempting to restart dashboard... 
Dec 15, 2021 10:50 AM  Failed start dashboard: The term 'Start-UDDashboard' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 

It appears Get-PSUDashboard doesn’t return anything, even without piping to Where-Object.

It’s failing to properly call the management API.

Dec 15, 2021 10:50 AM [error] Call failed. The SSL connection could not be established, see inner exception. GET https://localhost:443/api/v1/Dashboard 

You may need to set the URL manually.

Connect-PSUServer -ComputerName https://myServer:5000

The other thing is that you can update the Api \ URL in appsettings.json. It’s using the wrong host name and that’s why this warning is present.

Dec 15, 2021 10:50 AM [warning] Failed to verify module and server version. Call failed. The SSL connection could not be established, see inner exception. GET https://localhost:443/api/v1/version

I have used this cmdlet to restart my dashboards

function Restart-Dashboard{

    [CmdletBinding()]

        param(

        [Parameter(mandatory=$true)]

        $uri, 

    

        [Parameter(mandatory=$true)]

        $token

    )

    $t = Invoke-RestMethod  "$uri/api/v1/dashboard" -Headers @{ Authorization = "Bearer $token" }

    $id = $t[0].id

    #stop

    Invoke-RestMethod  "$uri/api/v1/dashboard/$id/status" -Headers @{ Authorization = "Bearer $token" } -Method Delete

    #start

    Invoke-RestMethod  "$uri/api/v1/dashboard/$id/status" -Headers @{ Authorization = "Bearer $token" } -Method Put

}
2 Likes

This worked perfectly! Thanks very much for sharing.

1 Like