<# .SYNOPSIS If the agent has a pending reboot display a notification on the screen. .DESCRIPTION This script will use the Toast function in Windows 11 in order to display a notification to users to let them know they need to reboot. This script can be used in order to let users reboot for Windows Updates for example. .OUTPUTS n/a Errorcodes: n/a .EXAMPLE Win - Toast notification for reboot.ps1 {{agent.needs_reboot}} .NOTES Author: D.de Kooker Source: n/a .CHANGELOG 24-06-2022 - Initial script. #> param ([Parameter(Mandatory)]$Needs_reboot) if ($Needs_reboot -ne "False") { Write-Host "Reboot is needed, preparing popup." #Checking if ToastReboot:// protocol handler is present New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -erroraction silentlycontinue | out-null $ProtocolHandler = get-item 'HKCR:\ToastReboot' -erroraction 'silentlycontinue' if (!$ProtocolHandler) { #create handler for reboot New-item 'HKCR:\ToastReboot' -force set-itemproperty 'HKCR:\ToastReboot' -name '(DEFAULT)' -value 'url:ToastReboot' -force set-itemproperty 'HKCR:\ToastReboot' -name 'URL Protocol' -value '' -force new-itemproperty -path 'HKCR:\ToastReboot' -propertytype dword -name 'EditFlags' -value 2162688 New-item 'HKCR:\ToastReboot\Shell\Open\command' -force set-itemproperty 'HKCR:\ToastReboot\Shell\Open\command' -name '(DEFAULT)' -value 'C:\Windows\System32\shutdown.exe -r -t 00' -force } if (!(Get-Module -ListAvailable -Name BurntToast)) { Write-Host "Cannot find BurntToast, installing module" Install-Module -Name BurntToast -Force } if (!(Get-Module -ListAvailable -Name RunAsUser)) { Write-Host "Cannot find RunAsUser, installing module" Install-Module -Name RunAsUser -Force } invoke-ascurrentuser -scriptblock { $heroimage = New-BTImage -Source 'https://dcomputers.nl/wp-content/uploads/2023/08/trmm-windowsupdates.png' -HeroImage $Text1 = New-BTText -Content "Dcomputers" $Text2 = New-BTText -Content "Er zijn op $(get-date) updates geinstalleerd en er is een herstart nodig. Herstart de computer nu of stel deze tot maximaal een dag uit." $Button = New-BTButton -Content "Herstart NU" -Arguments "ToastReboot:" -ActivationType Protocol $Button2 = New-BTButton -Content "Snooze" -snooze -id 'SnoozeTime' $5Min = New-BTSelectionBoxItem -Id 5 -Content '5 minuten' $10Min = New-BTSelectionBoxItem -Id 10 -Content '10 minuten' $1Hour = New-BTSelectionBoxItem -Id 60 -Content '1 uur' $4Hour = New-BTSelectionBoxItem -Id 240 -Content '4 uur' $8Hour = New-BTSelectionBoxItem -Id 480 -Content '8 uur' $1Day = New-BTSelectionBoxItem -Id 1440 -Content '1 dag' $Items = $5Min, $10Min, $1Hour, $4Hour, $8Hour, $1Day $SelectionBox = New-BTInput -Id 'SnoozeTime' -DefaultSelectionBoxItemId 10 -Items $Items $action = New-BTAction -Buttons $Button, $Button2 -inputs $SelectionBox $Binding = New-BTBinding -Children $text1, $text2 -HeroImage $heroimage $Visual = New-BTVisual -BindingGeneric $Binding $Content = New-BTContent -Visual $Visual -Actions $action Submit-BTNotification -Content $Content } exit 0 } else { Write-Host "There is no reboot needed" exit 0 }