Created
March 13, 2023 17:05
-
-
Save mother2110/0ec36851e8c4a00b649c4890af2fdc5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set security protocol to TLS 1.2 | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
# Install NuGet and BurntToast modules if not already installed | |
Install-PackageProvider -Name Nuget -MinimumVersion 2.8.5.201 -Force | |
# Add NuGet to system PATH | |
[System.Environment]::SetEnvironmentVariable("Path", "$env:Path;$nugetPath", "User") | |
if (!(Get-InstalledModule -Name BurntToast -ErrorAction SilentlyContinue)) { | |
# Install BurntToast module | |
Install-Module -Name BurntToast -Force | |
} | |
$regKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" | |
$regValue = "RebootRequired" | |
if (Test-Path $regKey) { | |
$rebootPending = (Get-ItemProperty $regKey).$regValue | |
if ($rebootPending) { | |
# Display a toast notification to prompt the user to reboot or snooze | |
$snoozeTime = New-TimeSpan -Minutes 120 # 2 hours | |
$snoozeAction = New-BurntToastNotificationAction -Arguments snooze -ActivationType protocol | |
$rebootAction = New-BurntToastNotificationAction -Arguments reboot -ActivationType protocol | |
New-BurntToastNotification -Text "A system reboot is required to complete updates." -SnoozeAndDismissLabel "Snooze" -SnoozeAndDismissAction $snoozeAction -SnoozeInterval $snoozeTime -Button $rebootAction -Sound "Notification.Default" | |
} | |
else { | |
Write-Host "No reboot required." | |
} | |
} | |
else { | |
Write-Warning "Registry key not found: $regKey" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment