Total Uptime Error



Noticed that if this is run against a server with 100% uptime and finds no events it's Total Uptime Value errors.

When it creates the start and end events, it updated the EventCount for the start event, but not for the end event.

This caused errors at Line 67 and in turn the $TotalUptime Value was calculated in-correct as the $StartUpPeriod was in-correct.

We corrected this by adding the following at Line 61 "$EventsCount = $EventsList.Count"
This was to update the EventsCount after the EndEvent is created.

It took a while to find as the majority of servers this wasn't a problem.

Hope this helps if someone else has this problem.




SwitchNikky wrote Oct 11, 2016 at 2:01 PM

Hi Mitch,

Thanks for your add. If I have a good understanding, the main problem is coming from the $StartUpPeriod which is not correctly set when the server has no downtime.

If you add "$EventsCount = $EventsList.Count" at line 61 you are changing the running test on $EventCount then the Else close is executed. This, make the $StartUpPeriod simply ignored in the case of a server with no downtime. Not an issue. But It changes the process when the event log's server contain an odd number of events. This can induce to miss an event.

Could you check if this command is running well on the server?:
Get-CimInstance Win32_OperatingSystem -ComputerName $HostName | Select-Object LastBootUpTime
If it is not the case, you can try to check WMI. The other option is to modify line 42:
$NewEvent.TimeGenerated = [datetime]::Today
in case the WMI fails.