1

I am looking to require restarts based on certain conditions within our environment. Currently we deploy Windows Updates via WSUS, but do not enforce forced restarts (this has a long history due to the type of environment I work in). We are looking utilize Task Scheduler to run a PowerShell script that does as follows:

  1. Checks if the system has a pending reboot due to Windows Update installation.
  2. If it does, check the system uptime.
  3. If the uptime is over 15 days (or maybe 10), alert the user that their system will be rebooted within 5 days automatically if they do not do so themselves.
  4. Repeat the alert once a day until the forced restart time is hit.

I have no idea where to begin with this. I know how to make WMI calls for system uptime, but not for pending reboots. Is Powershell the best thing for something like this, or is there a third-party program that might be more effective?

  • This question is really too broad for the scope of superuser. Powershell is certainly a valid tool for this. I would suggest doing some research on the steps that you have listed then post back here with specific problems that you have while writing the script. – EBGreen Jul 10 '15 at 19:48
  • You may want to use the PowerShell Windows Update module (gallery.technet.microsoft.com/scriptcenter/…) it has a cmdlet Get-WURebootStatus the rest is some logic in PowerShell and deciding where to store the current status. – Peter Hahndorf Jul 11 '15 at 4:22
  • Interesting set of behaviour requirements... I would skip the uptime check altogether. This would basically be a service/process that runs daily on a schedule? – xXhRQ8sD2L7Z Sep 8 '15 at 7:19
0

Starting a project can be daunting so just break it down into its individual components. How do you check pending reboots? How will you message your users? How will you schedule this?

https://gist.github.com/altrive/5329377 should get you started on reboot required.

Messaging your users could be as simple as msg * "This computer needs restarting" or you can use Send-MailMessage to email someone.

How are you going to test this each day? Task Scheduler seems your best option, but you'll have to solve the issue of knowing when the 5 days are up. I'd recommend saving a count or date in a file or the registry somewhere.

Then you just need to nest a bunch of IF statements and you're set =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.