PSRebootNotify.ps1
function Test-PendingReboot { if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true } if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true } if ( (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore).PendingFileRenameOperations | where {$_ -notlike "*users\*\appdata\local\temp*"}) { return $true } try { $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities" $status = $util.DetermineIfRebootPending() if(($status -ne $null) -and $status.RebootPending){ return $true } }catch{} return $false } function NotifyReboot{ Add-Type -AssemblyName System.Windows.Forms $global:balloon = New-Object System.Windows.Forms.NotifyIcon $path = (Get-Process -id $pid).Path $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) $balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning $balloon.BalloonTipText = 'Windows update has a reboot pending. Please reboot your computer' $balloon.BalloonTipTitle = "Attention" $balloon.Visible = $true $balloon.ShowBalloonTip(5000) } |