Jan 22 2021 07:09 AM
I wonder if anyone has any ideas on finding, using powershell, if a server is planning on rebooting anytime soon?
I can find out if a reboot is due for windows updates and a few other possible reasons, using powershell but if a reboot is waiting from running shutdown -r -t nnnnn then none of the places I know to look are helpful. Even Windows Admin Centre does not seem to know the server has a reboot pending. I have looked in Event viewer for a system log event ID13 but that may or may not tell me anything about an upcoming reboot.
A shutdown -a knows if a reboot is pending or not (it errors if not) but I can't find out where to look to find this information myself.
Any Ideas please?
Jan 22 2021 07:33 AM
SolutionSomething here might help.
How to Find Restart Info Using PowerShell and Windows Event Logs - WhatsUp Gold
Jan 22 2021 08:06 AM
@Dave Patrick Thanks that does help - I was using get get-eventlog to try and look at event ID13 and that was really not helpful.
Get-WinEvent is much more useful and actually returns the date and time of the scheduled reboot, and the reason.
Many thanks for that
Jan 22 2021 10:11 AM
Glad to hear it helps. Please don't forget to mark helpful replies.
Jan 27 2021 04:05 AM
So, for anyone else having this problem:
I could find nothing in registry that helped specifically for shutdown.exe
This https://www.powershellgallery.com/packages/PendingReboot/0.9.0.6 identified some reboot reasons I did not know about so I used this rather than my original code.
I then looked at the last event log entry for 1074
Get-WinEvent -ComputerName $computername -FilterHashtable @{logname = 'System'; id = 1074} -MaxEvents 1
by comparing the TimeCreated property of that result with the last boot time of the computer I could see if the event was historical or planned.
If planned, I then compared the TimeCreated property of event 1074 with 1075 to see it a shutdown -a had been used to cancel the reboot.