Public/OS/New-ScheduledReboot.ps1
<#
Copyright © 2024 Integris. For internal company use only. All rights reserved. #> FUNCTION New-ScheduledReboot { <# .SYNOPSIS Schedules a system reboot at a specified date and time. .DESCRIPTION This function schedules a system reboot by calculating the time difference between the current time and the specified date and time, then using the SHUTDOWN.exe command. .PARAMETER DateTime The date and time to schedule the reboot. .EXAMPLE New-ScheduledReboot -DateTime "2024-12-02T15:00:00" .NOTES The function uses the SHUTDOWN.exe command to schedule the reboot. #> PARAM ( [Parameter(Mandatory)] [DATETIME]$DateTime ) IF (($DateTime - (GET-Date)).TotalMinutes -lt 0) { RETURN "Scheduled reboot cannot occur in the past." } IF (($DateTime - (GET-Date)).TotalMinutes -lt 15) { Write-Warning "This reboot will occur within the next 15 minutes." $Confirmation = Read-Host "Are you sure? [Y to continue]" IF ($Confirmation -eq 'y' -or $Confirmation -eq 'yes') { } ELSE { RETURN "Scheduled reboot aborted." } } & "SHUTDOWN.exe" -R -T ([MATH]::ROUND((($DateTime - (GET-Date)).TotalSeconds),0)) RETURN "Reboot Scheduled for $DateTime (Approximately $([MATH]::ROUND((($DateTime - (GET-Date)).TotalHours),0)) Hours From Now)" } |