Interesting Reboot Challenge

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.

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
    
}

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?

Yes, you can use Start-Sleep.

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

You are welcome :wink:

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?

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

I wrote a short blog post on this a while back: Powershell tip: Wait for a certain time - Simon Wahlin

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.

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