Interesting Reboot Challenge

Welcome Forums General PowerShell Q&A Interesting Reboot Challenge

This topic contains 9 replies, has 4 voices, and was last updated by

 
Participant
4 years, 2 months ago.

  • Author
    Posts
  • #20321

    Participant
    Points: 1
    Rank: Member

    I'm presented with an interesting reboot challenge. I've a list of machines that I need to reboot. I can only reboot the machines in a two hour window in the early morning hours when I'm soundly asleep. So far this seems like a simple task. The complicated part? Reboot the machines in chunks of maybe 10,20, or 30. I cannot reboot them all at once.

    I'm thinking about getting content and storing that in a variable. I can feed that to a for each and restart computer. The timing, early morning, throws me and so does the chunks of machines.

    Your thoughts are greatly appreciated.

  • #20335

    Participant
    Points: 0
    Rank: Member

    If you want just a simple script you can use very simple one:

    $ComputerList = "Comp1", "Comp2", "Comp3"
    
    Foreach ($Comp in $ComputerList)
    {
        Restart-Computer -ComputerName $Comp
        
    }
    
  • #20340

    Participant
    Points: 1
    Rank: Member

    Thanks Ondrej. The challenge is to not reboot them all at once or immediately following each other. I'm wondering if putting in a pause for two minutes between each computer would do the trick?

    • #20341

      Participant
      Points: 0
      Rank: Member

      Yes, you can use Start-Sleep.

  • #20358

    Participant
    Points: 1
    Rank: Member

    Ondrej, simple enough. Thank you for the valued input.

    • #20360

      Participant
      Points: 0
      Rank: Member

      You are welcome 😉

  • #20376

    Participant
    Points: 1
    Rank: Member

    I just realized that I did not solve the timing problem. I guess I can just remotely create a windows scheduled task to time it. Not sure that is the best approach?

  • #20377

    Participant
    Points: 0
    Rank: Member

    You can use a while-loop to wait until it is time.

    I wrote a short blog post on this a while back: http://blog.simonw.se/powershell-tip-wait-for-a-certain-time/

  • #20378

    Participant
    Points: 1
    Rank: Member

    You can use a while-loop to wait until it is time.

    I wrote a short blog post on this a while back: http://blog.simonw.se/powershell-tip-wait-for-a-certain-time/

    That looks interesting. The for each can go right into the do part.

  • #20380

    Participant
    Points: 1
    Rank: Member

    you can also select only few computers at a time...
    reboot sleep ping/test
    continue

The topic ‘Interesting Reboot Challenge’ is closed to new replies.