hello.
Not loking for any help. Im lokoing to share what ive created with the hope it may help someone else? My requirement was to report on server availability for the previous month as a percentage. Couldnt find these requirements anywhere. Please see below. Hope this helps someone.
<# .SYNOPSIS Simple script to provide server availability uptime statistics .DESCRIPTION This script will define the amount of time a server has been unavaialble for in the past 31 days. Scans the system event log for 6005 and 6006 event id's using an XML filter (faster). These event id's are startup and shutdown entires, the first and last thing that happens on a server. We subtract the amount of time between the two events and calculate the down time. .NOTES Author Matt Nicholas #> #$Diff = 86400000*$DaysAgo # Milliseconds in a day $startDate =get-date $(get-date).AddMonths(-1).ToString("01/MM/yyyy") $endDate =$startDate.AddMonths(1).AddMilliseconds(-1) $XMLFilter="<QueryList> <Query Id=`"0`" Path=`"System`"> <Select Path=`"System`">*[System[( (EventID = 6005 or EventID = 6006) ) and TimeCreated[@SystemTime>=' $($startDate.tostring("yyyy-MM-dd"))T00:00:00.000Z' and @SystemTime<='$($endDate.tostring("yyyy-MM-dd"))T22:59:59.999Z']]]</Select> </Query> </QueryList>" # Get the list of tartget servers [ string[]]$Computers= (Get-Content"c:\utils\servers.txt") # Foreach target server ForEach ($computerin$Computers) { # Get the reboot info from event log on current target server $RebootEvents=get-winevent-FilterXML$XMLFilter-computername$Computer|sort-object-Descending-propertyTimeCreated $down=$null $up=$null [timespan]$TotalDownTime=New-TimeSpan Foreach($rebootEventin$RebootEvents) { if ($rebootEvent.ID -eq6006) { $down=$rebootEvent.TimeCreated } #end if eventID Else { $up=$rebootEvent.TimeCreated } #end else if($down-AND$up) { if($down-ge$up) { Write-Host-foregroundColorRed"*** Invalid data. Ignoring $($up)" $up=$down } #end if down is greater than up [timespan]$CurrentDownTime=new-TimeSpan-start$down-end$up $TotalDownTime+=$currentDownTime $down=$null $up=$null } #end if down and up } #end foreach $periodDifference=$endDate-$startdate $minutesInMonth=$diff.mins $minutesInDay=24*60 $percentUpTime= (100- ($TotalDownTime.TotalMinutes/$periodDifference.TotalMinutes)*100) "This computes to $($percentUptime.ToString("###.###")) percent uptime on $computer for the previous month period" }