Would it be a good idea to have something like “restart Service” in the UI somewhere? Maybe under the platform somewhere?
We run ours as a service and I tend to reboot PSU to test certain functionality and I always have to fire up services.msc.
Would it be a good idea to have something like “restart Service” in the UI somewhere? Maybe under the platform somewhere?
We run ours as a service and I tend to reboot PSU to test certain functionality and I always have to fire up services.msc.
I think that would be handy. In the interim, I’d think you could use the PowerShell cmdlets Restart-Computer
or Restart-Service
in a script inside of PSU, lock it down via roles or such to only certain people, and just use PSU’s “run” button to trigger it.
The obvious caveat would be, if PSU is not responding to be able to do that you’d still have to rely on other methods.
Why don’t you create an app that offers that functionality?
I don’t use apps tbh.
I’ve already got a dashboard for doing just this. It might need a little tweaking for a different environment, but the bones should be there.
New-UDDashboard -Title 'Restart Powershell Universal Service' -Pages @(
New-UDPage -Name 'Restart Powershell Universal Service' -id 'RestartPowershellUniversalService' -Content {
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Warning"
New-UDTypography "Warning"
} -Content {
New-UDHtml "Restarting the Powershell Universal service will terminate existing connections. Only do this if some dashboards are experiencing problems.<br><br>Restart the Powershell Universal service?"
} -Footer {
New-UDButton -Icon (New-UDIcon -Icon 'Check') -Text "Yes" -OnClick {
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Spinner" -Spin
New-UDTypography "Working ..."
}
} -Content {
New-UDHtml "Powershell Universal service is now restarting on remote servers."
} -Footer {
}
# Restart remote
$Servers = Get-PSUComputer | Where {$_.Name -ne $Env:ComputerName} | Select -ExpandProperty Name
Foreach ($Server in $Servers) {
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Spinner" -Spin
New-UDTypography "Working ..."
}
} -Content {
New-UDHtml "Powershell Universal service is now restarting on $Server."
} -Footer {
}
Invoke-Command -ComputerName $Server -ScriptBlock {
Get-Service -Name 'PowershellUniversal' | Restart-Service -Force
} -Credential $Secret:
$Seconds = 0
Do {
Start-Sleep -s 1
$Seconds += 1
$Status = Invoke-Command -ComputerName $Server -ScriptBlock {
Get-Service -Name 'PowershellUniversal' | Select -ExpandProperty Status
} -Credential $Secret:
} Until ($Status.Value -eq 'StartPending' -or $Status.Value -eq 'Starting' -or $Status.Value -eq 'Running' -or $Seconds -gt 180)
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Spinner" -Spin
New-UDTypography "Working ..."
}
} -Content {
New-UDHtml "Powershell Universal service is now starting on $Server."
} -Footer {
}
$Seconds = 0
Do {
Start-Sleep -s 1
$Seconds += 1
$Status = Invoke-Command -ComputerName $Server -ScriptBlock {
Get-Service -Name 'PowershellUniversal' | Select -ExpandProperty Status
} -Credential $Secret:
} Until ($Status.Value -eq 'Running' -or $Seconds -gt 180)
Hide-UDModal
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Spinner" -Spin
New-UDTypography "Working ..."
}
} -Content {
New-UDHtml "Waiting for Powershell Universal $Server to be back online."
} -Footer {
}
# Sleep until back online
$Seconds = 0
Do {
Start-Sleep -s 5
$Seconds += 5
$Status = (Get-PSUComputer | Where {$_.Name -eq $Server} | Select -ExpandProperty Status)
} Until ( $Status -eq 'Online' -or $Seconds -gt 180 )
Hide-UDModal
}
Hide-UDModal
Show-UDModal -Persistent -Header {
New-UDElement -tag 'Div' -Content {
New-UDIcon -Icon "Spinner" -Spin
New-UDTypography "Working ..."
} -Content {
New-UDHtml "Powershell Universal service is now restarting on the local server. Refresh the page when you receive the timeout message."
} -Footer {
}
# Restart local
Restart-Service -Name 'PowershellUniversal' -Force
Hide-UDModal
} -ShowLoading
New-UDButton -Icon (New-UDIcon -Icon 'XMark') -Text "No" -OnClick {
Hide-UDModal
}
}
} -LoadNavigation $Navigation
)