Hi
I got below script from technet link (https://technet.microsoft.com/en-us/magazine/2008.12.heyscriptingguy.aspx) for server/DCs UPtime in percentage form.
I am trying to run it for multiplese domain controllers which are in CSV file as input.
But I am getting display output only one DC, not for all other dcs which are in CSV file
Please help me or guide me to get this.
##############
Import-CSV "D:\gops\serverlist.csv" | foreach {
Param($servername,$NumberOfDays = 30, [switch]$debug)
if($debug) { $DebugPreference = " continue" }
[timespan]$uptime = New-TimeSpan -start 0 -end 0
$currentTime = get-Date
$startUpID = 6005
$shutDownID = 6006
$unexpectedshutdown = 6008
$minutesInPeriod = (24*60)*$NumberOfDays
$startingDate = (Get-Date -Hour 00 -Minute 00 -Second 00).adddays(-$numberOfDays)
Write-debug "'$uptime $uptime" ; start-sleep -s 1
write-debug "'$currentTime $currentTime" ; start-sleep -s 1
write-debug "'$startingDate $startingDate" ; start-sleep -s 1
$servername = $_.servername
$events = Get-EventLog -LogName system -ComputerName $servername -ErrorAction SilentlyContinue |
Where-Object { $_.eventID -eq $startUpID -OR $_.eventID -eq $shutDownID -OR $_.eventid -eq $unexpectedshutdown `
-and $_.TimeGenerated -ge $startingDate }
write-debug "'$events $($events)" ; start-sleep -s 1
$sortedList = New-object system.collections.sortedlist
ForEach($event in $events)
{
$sortedList.Add( $event.timeGenerated, $event.eventID )
} #end foreach event
$uptime = $currentTime - $sortedList.keys[$($sortedList.Keys.Count-1)]
Write-Debug "Current uptime $uptime"
For($item = $sortedList.Count-2 ; $item -ge 0 ; $item -- )
{
Write-Debug "$item `t `t $($sortedList.GetByIndex($item)) `t `
$($sortedList.Keys[$item])"
if($sortedList.GetByIndex($item) -eq $startUpID)
{
$uptime += ($sortedList.Keys[$item+1] - $sortedList.Keys[$item])
Write-Debug "adding uptime. `t uptime is now: $uptime"
} #end if
} #end for item
"Total up time on $env:computername since $startingDate is " + "{0:n2}" -f `
$uptime.TotalMinutes + " minutes."
$UpTimeMinutes = $Uptime.TotalMinutes
$percentDownTime = "{0:n2}" -f (100 - ($UpTimeMinutes/$minutesInPeriod)*100)
$percentUpTime = 100 - $percentDowntime
"$percentDowntime% downtime and $percentUpTime% uptime."
$props = @{
ServerName = $servername
Uptime = $UpTimeMinutes
PercentUptime = $percentUpTime
PercentDowntime = $percentDowntime
}
New-Object PsObject -Property $props
}
##################################