I have this following script so I can force the download and installations of Windows updates.
I’m improving it so that after the installations of updates it gives me a pop-up message saying in 24h the computer will restart and 10 minutes before restarting gives another message saying the computer will restart in 10 min.
The question is I can’t do the script to give the 10 min message before restarting.
Can you help me with this issue please?
This is a part of my script just to show the notifications.
function Show-BalloonTip {
param (
[string]$Title,
[string]$Message
)
$notification = New-Object -ComObject WScript.Shell
$notification.Popup($Message, 10, $Title, 0x1)
}
function Schedule-Tasks {
# Define o atraso para 24 horas e o aviso para 23 horas e 50 minutos
$RebootDelayMinutes = 24 * 60
$WarningDelayMinutes = $RebootDelayMinutes - 10
# Calcula os horários de início com base nos atrasos
$rebootTime = (Get-Date).AddMinutes($RebootDelayMinutes).ToString("HH:mm")
$warningTime = (Get-Date).AddMinutes($WarningDelayMinutes).ToString("HH:mm")
# Cria a tarefa agendada para o reinício
schtasks /create /tn "ScheduledReboot" /tr "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -Command `"shutdown /r /f`"" /sc once /st $rebootTime /ru SYSTEM /f
# Cria um script temporário para a mensagem de aviso
$scriptPath = "C:ProgramDataRebootWarning.ps1"
$scriptContent = @"
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('The system will reboot in 10 minutes.', 'Reboot Warning')
"@
Set-Content -Path $scriptPath -Value $scriptContent
# Cria a tarefa agendada para a mensagem de aviso
$escapedScriptPath = $scriptPath -replace ' ', '` '
schtasks /create /tn "RebootWarning" /tr "powershell.exe -File `"$escapedScriptPath`"" /sc once /st $warningTime /ru SYSTEM /f
}
if (!$ListOnly -and !$NoAutoReboot) {
Schedule-Tasks
Show-BalloonTip -Title "Windows Updates" -Message "Updates installed. The system will reboot in 30 minutes. A warning will be displayed 10 minutes before the reboot."
}
I’ve tried everything i remember to do.
Bu my knowledge it’s a little bit limited.