Advertisement
Cogger

Reboot-At-Time.ps1

Jan 10th, 2022
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $archour = Read-Host -Prompt 'What hour, in 24 hour format, do you want to reboot?'
  2. $arcminu = Read-Host -Prompt 'What minute do you want to reboot?'
  3.  
  4. $maxRetries = 9999999; $retryCount = 0; $completed = $false
  5. while (-not $completed) {
  6.     Clear-Variable -Name "TimeNow"  -EA SilentlyContinue
  7.     Clear-Variable -Name "TimeDial"  -EA SilentlyContinue
  8.  
  9.     $TimeNow = (Get-Date).ToString('HH:mm')
  10.     $TimeDial = $TimeNow.split(':')
  11.  
  12.  
  13.     if ($TimeDial[0] -gt $archour) {
  14.        
  15.         if ($TimeDial[1] -gt $arcminu){
  16.             Restart-Computer -ComputerName $env:COMPUTERNAME -Force
  17.             $completed = $true
  18.         }
  19.     }
  20.     else {
  21.         if ($retryCount -ge $maxRetries) {
  22.            
  23.         } else {
  24.             Write-Verbose "It is not time yet, trying again in 60 seconds."
  25.             Start-Sleep '60'
  26.             $retryCount++
  27.         }
  28.     }
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement