PowerShell: calculating uptime for Windows server (PowerUptime)

Introduction

The utility uptime.exe (from CodePlex) does not provide all data presents in uptime.exe (from NT 4.0). And uptime.exe (NT 4.0) is crashing and generating events 1000 on many servers. The workaround to make utptime.exe (NT 4.0) working is to clear the event log. This is acceptable in some environments but as soon as you are managing a significant number of servers, it becomes unacceptable for a lot of reasons.  The main reason is justifying by itself the existence of logs so I suppose, as a reader of this article, you are aware about.

Links to other uptime solution:

uptime.exe (CodePlex) http://uptimeexe.codeplex.com/

uptime.exe (NT 4.0) http://www.microsoft.com/en-us/download/details.aspx?id=14732

 

Outputs of uptime.exe

The output of uptime.exe (from CodePlex) is:

 

C:\>uptime
 08:20:14 uptime 08:48:27

The Output of uptime.exe (from NT 4.0) is

 

C:\>uptime /a
Uptime Report for: \\computer_name

Current OS: Windows Server 2008 R2 Enterprise Multiprocessor Free.
Time Zone: @tzres.dll,-261

System Events as of 12/09/2013 11:00:23:

Date:      Time:        Event:               Comment:
---------- -----------  -------------------  ----------------------------------

10/12/2012    16:02:14  Shutdown
10/12/2012    16:05:07  Boot                 Prior downtime:0d 0h:2m:53s
30/05/2013    23:13:46  Shutdown             Prior uptime:171d 6h:8m:39s
30/05/2013    23:17:01  Boot                 Prior downtime:0d 0h:3m:15s
30/05/2013    23:24:20  Shutdown             Prior uptime:0d 0h:7m:19s
30/05/2013    23:27:12  Boot                 Prior downtime:0d 0h:2m:52s
11/08/2013    00:06:22  Shutdown             Prior uptime:72d 0h:39m:10s
11/08/2013    00:10:06  Boot                 Prior downtime:0d 0h:3m:44s
30/08/2013    16:09:04  Shutdown             Prior uptime:19d 15h:58m:58s
30/08/2013    16:12:12  Boot                 Prior downtime:0d 0h:3m:8s

Current System Uptime: 12 day(s), 18 hour(s), 48 minute(s), 33 second(s)


-------------------------------------------------------------------------------


Since 10/12/2012:

           System Availability: 99.9960%
                  Total Uptime: 275d 17h:42m:17s
                Total Downtime: 0d 0h:15m:52s
                 Total Reboots: 5
     Mean Time Between Reboots: 55.15 days
             Total Bluescreens: 0
    Total Application Failures: 0

The difference is big between these outputs and we have good reasons to do not provide all data included in uptime.exe (NT 4.0).

 

- The nature of how we can get downtime periods are the cause. The only way to get the downtimes is to use the system event log. So uptime.exe (CodePlex) do not read logs and take the last known start date: the one provided by WMI LastBootUpTime and the  uptime.exe (NT 4.0) read the log and try to calculate a downtime period. Uptime.exe (NT 4.0) is crashing when it reads 2 eventID 6005 consecutively without an eventID 6006 between. So you are not able to get the uptime with uptime.exe (NT 4.0)

The unexpected shutdown are ignored in the uptime utilities I saw on Technet. As it was with uptime2.exe (from Techibee).

To explain it in picture:

<picture missing>

You can see 2 startup events (EventID 6005) without shutdown event (EventID 6006).

These utilities, maybe to stay compatible with the workstation's versions of Windows, do not deal with the 6008 event.

The main inconvenient is these downtime periods are not summarized. The uptime become not accurate and a simple ping robot is becoming more accurate.

 

Period of calculation for the uptime

None of these utilities are permitting to manage the period you want your uptime. Wich is generating another problem to deal with: the purge of the system event log. Most of servers have a limited disk space reserved for logs and they are purged mostly based on the size. Once this sized reached, the logs are overwritten and events lost.

Downloads

Download PowerUptime at https://poweruptime.codeplex.com/