ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    PWSH: Reboot servers from a file

    Developer Discussion
    1
    1
    690
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • GreyG
      Grey
      last edited by

      A little script I wrote to reboot a bunch of servers at a specific, calculated time. You can adjust the filename or time in the header. Default time is 730 pm. You need winrm enabled on all the target systems, and I don't know what the limit would be on server count. If you run a NOC, warn them before all the servers reboot at exactly the same time. lol!

      ###########
      #Boot systems in a file at 730 pm

      $file = "$($ENV:USERPROFILE)\desktop\systems.txt"
      $target = Get-Date -Hour 19 -Minute 30 -Second 0

      #don't change anything below here
      $systems = get-content $file
      $utz = Get-Date -Hour 19 -Minute 30 -Second 0 -UFormat "%Z"
      $now = $(Get-Date)
      $serverTZ = (get-timezone).id
      $seconds = ($target - $now).TotalSeconds
      $final = [math]::Round($seconds)
      $final = $final - 15
      Write-Host -ForegroundColor cyan -NoNewline "nSeconds until $target $serverTZ ($utz UTC):"
      write-host -ForegroundColor Yellow " $final"
      $final |clip
      Write-Host -ForegroundColor Cyan "15 second delay to cancel a scheduled reboot for $($($systems).count) systems:`n$systems"
      #Write-Progress -SecondsRemaining 15 -Activity "Reboot schedule countdown."
      Start-Sleep -Seconds 15
      Invoke-Command -ComputerName $Systems -ScriptBlock {shutdown -r -t $using:final}
      Write-Host -ForegroundColor Cyan "End of Line"

      1 Reply Last reply Reply Quote 2
      • 1 / 1
      • First post
        Last post