A small one this time. Whether it is Azure servers, customer servers or workstations ... there can be many reasons why a device can not be running 24/7 and reboots need to happen.
As an example, Azure servers that have been set to turn off after work hours and turn on in the morning. To realize this, you must have set rules or other automation tools to have it shut down and start up again. However, can you trust on it always working? Maybe the server has been online for the last few weeks without you noticing!
The script below checks how long a device has been active for and executes actions depending on the result.
With $days you can set the maximal amount of days the device is allowed to be running.
The line telling you the device is active for longer than you have set can be adjusted to do anything. Whether it is to send a mail, create an event log, shut down the server or any other action you can think of in Powershell.
Same goes for the reaction when the last boot has been less time ago than set limit.
May this inform you about devices being actively running for too long and help you avoid future issues.
Categories: Powershell, Windows, Server, Workstation, Script
Patrick Berger AKA Powershellder.
[ i ] Parallax section below. Click on the section below to upload image. Don't worry if it looks weird in the Weebly editor. It'll look normal on your published site.
To edit or delete your image, press the "toggle" button below. Then, hover over your image until a popup appears with the "edit" and "delete" options. If you don't want a white content section, leave it blank. It will disappear on your live website.