Files
windows-builder/includes/$OEM$/$$/OEM/scripts/windowsupdate/Preview-Notifications.ps1
2026-06-02 03:37:09 -07:00

262 lines
13 KiB
PowerShell

<#
.SYNOPSIS
Preview Windows Update Notifications
.DESCRIPTION
Test script to preview all notification types without checking for real updates
.NOTES
Author: oxmc
#>
# Import notification module
Import-Module "$PSScriptRoot\UpdateNotifications.psm1" -Force
Write-Host "=== Windows Update Notification Preview ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "This script will show you all the different notifications" -ForegroundColor Yellow
Write-Host ""
# Create some fake updates for demonstration
$fakeUpdates = @(
[PSCustomObject]@{
Title = "2024-01 Cumulative Update for Windows 11 Version 23H2 for x64-based Systems (KB5034123)"
Description = "This security update includes improvements and fixes that are part of the latest servicing stack update for Windows. Installing this update ensures that your computer can receive future Windows updates."
MaxDownloadSize = 125000000
Type = 1
Categories = @([PSCustomObject]@{ Name = "Critical Updates" })
},
[PSCustomObject]@{
Title = "Windows Defender Antivirus Definition Update - KB2267602 (Definition 1.403.2345.0)"
Description = "Install this update to revise the definition files that are used to detect viruses, spyware, and other potentially unwanted software."
MaxDownloadSize = 45000000
Type = 1
Categories = @([PSCustomObject]@{ Name = "Definition Updates" })
},
[PSCustomObject]@{
Title = "2024-01 Security Update for .NET Framework 4.8 for Windows 11 (KB5034122)"
Description = "A security issue has been identified in a Microsoft software product that could affect your system. You can help protect your system by installing this update from Microsoft."
MaxDownloadSize = 98000000
Type = 1
Categories = @([PSCustomObject]@{ Name = "Security Updates" })
},
[PSCustomObject]@{
Title = "Intel - System - 10.1.19.5 - Graphics Driver Update"
Description = "This package provides the Intel Graphics Driver and is supported on OptiPlex, Precision, and Latitude models that are running the following Windows Operating Systems: Windows 10."
MaxDownloadSize = 148000000
Type = 2
Categories = @([PSCustomObject]@{ Name = "Drivers" })
},
[PSCustomObject]@{
Title = "2024-01 Servicing Stack Update for Windows 11 Version 23H2 (KB5034121)"
Description = "Install this update to resolve issues in Windows. For a complete listing of the issues that are included in this update, see the associated Microsoft Knowledge Base article."
MaxDownloadSize = 12000000
Type = 1
Categories = @([PSCustomObject]@{ Name = "Important" })
}
)
function Show-Menu {
Clear-Host
Write-Host "=== Notification Preview Menu ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "1. Preview 'Updates Available' Toast Notification" -ForegroundColor White
Write-Host "2. Preview 'Installing Updates' Toast Notification" -ForegroundColor White
Write-Host "3. Preview 'Updates Complete' Toast Notification" -ForegroundColor White
Write-Host "4. Preview 'Updates Complete with Reboot' Toast Notification" -ForegroundColor White
Write-Host "5. Preview 'Installation Failed' Toast Notification" -ForegroundColor White
Write-Host "6. Preview 'Reboot Required' Toast Notification" -ForegroundColor White
Write-Host ""
Write-Host "7. Preview Balloon Tip Notification (Info)" -ForegroundColor White
Write-Host "8. Preview Balloon Tip Notification (Warning)" -ForegroundColor White
Write-Host "9. Preview Balloon Tip Notification (Error)" -ForegroundColor White
Write-Host ""
Write-Host "10. Preview Detailed Update Window (Interactive)" -ForegroundColor Green
Write-Host "11. Preview Installation Progress Window" -ForegroundColor Green
Write-Host ""
Write-Host "12. Show All Notifications (One by One)" -ForegroundColor Yellow
Write-Host ""
Write-Host "Q. Quit" -ForegroundColor Red
Write-Host ""
}
do {
Show-Menu
Write-Host "Select an option: " -NoNewline -ForegroundColor Yellow
$choice = Read-Host
switch ($choice) {
"1" {
Write-Host "`nShowing 'Updates Available' toast notification..." -ForegroundColor Green
Show-UpdateAvailableToast -UpdateCount 5 -Updates $fakeUpdates
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"2" {
Write-Host "`nShowing 'Installing Updates' toast notification..." -ForegroundColor Green
Show-UpdateInstallingToast -UpdateCount 5
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"3" {
Write-Host "`nShowing 'Updates Complete' toast notification..." -ForegroundColor Green
Show-UpdateCompleteToast -SuccessCount 5 -RebootRequired $false
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"4" {
Write-Host "`nShowing 'Updates Complete with Reboot' toast notification..." -ForegroundColor Green
Show-UpdateCompleteToast -SuccessCount 5 -RebootRequired $true
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"5" {
Write-Host "`nShowing 'Installation Failed' toast notification..." -ForegroundColor Green
Show-UpdateFailedToast -ErrorMessage "Error code: 0x80070002 - One or more updates failed to install"
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"6" {
Write-Host "`nShowing 'Reboot Required' toast notification..." -ForegroundColor Green
Show-RebootRequiredToast -MinutesUntilReboot 15
Write-Host "Check your Action Center (Win+A) to see the notification!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"7" {
Write-Host "`nShowing Info balloon notification..." -ForegroundColor Green
Write-Host "Look at your system tray!" -ForegroundColor Cyan
Show-BalloonNotification -Title "Windows Update Manager" `
-Message "5 updates are available for your computer" `
-Icon "Info" `
-Duration 5000
Write-Host "`nBalloon notification shown!" -ForegroundColor Green
Start-Sleep -Seconds 1
}
"8" {
Write-Host "`nShowing Warning balloon notification..." -ForegroundColor Green
Write-Host "Look at your system tray!" -ForegroundColor Cyan
Show-BalloonNotification -Title "Restart Required" `
-Message "Your computer needs to restart to complete updates" `
-Icon "Warning" `
-Duration 5000
Write-Host "`nBalloon notification shown!" -ForegroundColor Green
Start-Sleep -Seconds 1
}
"9" {
Write-Host "`nShowing Error balloon notification..." -ForegroundColor Green
Write-Host "Look at your system tray!" -ForegroundColor Cyan
Show-BalloonNotification -Title "Update Failed" `
-Message "Some updates could not be installed. Error code: 0x80070002" `
-Icon "Error" `
-Duration 5000
Write-Host "`nBalloon notification shown!" -ForegroundColor Green
Start-Sleep -Seconds 1
}
"10" {
Write-Host "`nOpening detailed update window..." -ForegroundColor Green
Write-Host "This is interactive - you can select updates and click buttons!" -ForegroundColor Cyan
Write-Host ""
$result = Show-UpdateDetailsWindow -Updates $fakeUpdates
Write-Host "`nYou selected: $($result.Action)" -ForegroundColor Yellow
if ($result.Action -eq "Install") {
Write-Host "Updates selected: $($result.Updates.Count)" -ForegroundColor Green
foreach ($update in $result.Updates) {
Write-Host " - $($update.Title)" -ForegroundColor Gray
}
}
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"11" {
Write-Host "`nShowing installation progress window..." -ForegroundColor Green
Write-Host "This will show for 10 seconds..." -ForegroundColor Cyan
$progressForm = Show-InstallationProgressWindow -Updates $fakeUpdates
# Simulate progress
for ($i = 1; $i -le 5; $i++) {
Start-Sleep -Seconds 2
Update-InstallationProgress -Form $progressForm -Current $i -Total 5 -CurrentUpdate $fakeUpdates[$i-1].Title
}
if ($progressForm -and -not $progressForm.IsDisposed) {
$progressForm.Close()
$progressForm.Dispose()
}
Write-Host "`nProgress window closed!" -ForegroundColor Green
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"12" {
Write-Host "`nShowing all notifications sequentially..." -ForegroundColor Green
Write-Host ""
Write-Host "1/9 - Updates Available (Toast)" -ForegroundColor Cyan
Show-UpdateAvailableToast -UpdateCount 5 -Updates $fakeUpdates
Start-Sleep -Seconds 3
Write-Host "2/9 - Installing Updates (Toast)" -ForegroundColor Cyan
Show-UpdateInstallingToast -UpdateCount 5
Start-Sleep -Seconds 3
Write-Host "3/9 - Updates Complete (Toast)" -ForegroundColor Cyan
Show-UpdateCompleteToast -SuccessCount 5 -RebootRequired $false
Start-Sleep -Seconds 3
Write-Host "4/9 - Reboot Required (Toast)" -ForegroundColor Cyan
Show-RebootRequiredToast -MinutesUntilReboot 15
Start-Sleep -Seconds 3
Write-Host "5/9 - Installation Failed (Toast)" -ForegroundColor Cyan
Show-UpdateFailedToast -ErrorMessage "Error code: 0x80070002"
Start-Sleep -Seconds 3
Write-Host "6/9 - Info Balloon" -ForegroundColor Cyan
Show-BalloonNotification -Title "Updates Available" -Message "5 updates ready" -Icon "Info" -Duration 3000
Write-Host "7/9 - Warning Balloon" -ForegroundColor Cyan
Show-BalloonNotification -Title "Restart Required" -Message "Please restart soon" -Icon "Warning" -Duration 3000
Write-Host "8/9 - Error Balloon" -ForegroundColor Cyan
Show-BalloonNotification -Title "Update Failed" -Message "Installation error" -Icon "Error" -Duration 3000
Write-Host "9/9 - Detailed Window (will open now)" -ForegroundColor Cyan
Start-Sleep -Seconds 2
$null = Show-UpdateDetailsWindow -Updates $fakeUpdates
Write-Host "`nAll notifications shown!" -ForegroundColor Green
Write-Host "Check your Action Center (Win+A) to see the toast notifications!" -ForegroundColor Cyan
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
"Q" {
Write-Host "`nExiting..." -ForegroundColor Green
}
default {
Write-Host "`nInvalid option. Please try again." -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
} while ($choice -ne "Q" -and $choice -ne "q")
Write-Host "`nThanks for previewing the notifications!" -ForegroundColor Cyan