How can I easily see a history of every time my Windows Server has restarted or shutdown and the reason why, including user-initiated, system-initiated, and system crashed?
The Windows Event Log is an obvious answer but what is the complete list of events that I should view?
I found these posts that partially answer my question:
- Windows server last reboot time includes several answers that partially address the full restart history
- View Shutdown Event Tracker logs under Windows Server 2008 R2 includes an additional event id
- Event Log time when Computer Start up / boot up includes some of the same event ids
but those don't cover every scenario AFAIK and the info is hard to understand because it is spread across multiple answers.
I have several versions of Windows Server so a solution that works for at least versions 2008, 2008 R2, 2012, and 2012 R2 would be ideal.
The clearest most succinct answer I could find is:
which lists these event ids to monitor (quoted but edited and reformatted from article):
Add to that a couple more from the Server Fault answers listed in my OP:
Did I miss any?
Turning @user10082 comment into an answer. The proposed solution is a one-liner, as Powershell script:
Here is the output:
I would simply leave this as a comment since JohnC has basically covered everything, but I am not allowed to do so yet.
The events he described have been used for quite a while, so they will work for any of the OS you mentioned, as well as their desktop brethren. The event ID pages He linked to, such as the one for 6006 on TechNet, mention Windows Server 2003.
If there was an elegant shutdown, user initiated or otherwise, you should also see some Event ID 7036 telling you that various services "entered the stopped state." As the machine starts up again, you will see more 7036s announcing that services are entering the running state.
I prefer to accomplish activities from command line. Here's the beginning of a snippet you can leverage. This shows the most recent 30,000 system records and returns the reboots within those records.
Building on @JohnC s answer and extending it
You could use an XML filter like:
You can replace 172800000 with the below values for the time range:
86400000 - Last 24 hours
172800000 - Last 2 Days
604800000 - Last 7 Days
This will show much more detail from the time when the server/pc went offline It includes Kernel-Power, User32 and EventLog events.
Short and concise one liner to get reboot and startup time of last 8 hours from a remote machine using SysInternals
psloglist
and the event id's from above:The only thing missing (for me) is the event id for "logon dialog ready for user" equivalent. That seems to hard to find (What can I query to see if Windows is booted and done with updates?)