Dear All,
we are creating a script which will check if any system has not been rebooted in last 20 days and give a popup to logged in user with 3 buttons [Restart, snooze, dismiss]. created below script but not sure what i'm missing as i'm not getting popup. any help will be highly appreciated.
===========================================
Get the WMI object for the operating system
$os = Get-WmiObject -Class Win32_OperatingSystem
Convert the last boot up time and the current time to datetime objects
$lastBootUpTime = [System.Management.ManagementDateTimeConverter]::ToDateTime($os.LastBootUpTime)
$currentTime = [System.Management.ManagementDateTimeConverter]::ToDateTime($os.LocalDateTime)
Calculate the uptime in days
$uptime = ($currentTime - $lastBootUpTime).Days
Check if the uptime is more than 20 days
if ($uptime -gt 20) {
Import the BurntToast module for creating toast notifications
Import-Module BurntToast
New-BurntToastNotification -Text "System Restart Required", "Your system has been running for more than 20 days. Please save your work and close all applications. The system will restart in 10 minutes." -AppLogo "C:\Windows\System32\oobe\info\logo.png" -Button @(
New-BTButton -Content "Restart Now" -Arguments "RestartNow" -ActivationType Protocol,
New-BTButton -Content "Snooze" -Arguments "Snooze" -ActivationType Protocol,
New-BTButton -Content "Dismiss" -Arguments "Dismiss" -ActivationType Protocol
)
Register-EngineEvent -SourceIdentifier "Microsoft.PowerShell.BurntToastNotification" -Action {
$button = $event.SourceEventArgs.Argument
if ($button -eq "RestartNow") {
Restart-Computer -Force
}
elseif ($button -eq "Snooze") {
shutdown /s /t 600
}
elseif ($button -eq "Dismiss") {
No action required
}
}
}
============================================