Skip to content

Commit 87ef27d

Browse files
authored
Merge pull request #11 from sawft99/Uptime-Patch
Update CheckForRestartsAndUptime.ps1
2 parents 3dee21e + c30b761 commit 87ef27d

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

CheckForRestartsAndUptime.ps1

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
#Reference
44
#Event Log ID | Meaning
5-
#41 | The system has rebooted without cleanly shutting down first
6-
#1074 | The system has been shutdown properly by a user or process
7-
#1076 | Follows after EventLog.Id ID 6008 and means that the first user with shutdown privileges logged on to the server after an unexpected restart or shutdown and specified the cause
8-
#6005 | The EventLog.Id Log service was started. Indicates the system startup
9-
#6006 | The EventLog.Id Log service was stopped. Indicates the proper system shutdown
10-
#6008 | The previous system shutdown was unexpected
11-
#6009 | The operating system version detected at the system startup
12-
#6013 | The system uptime in seconds
5+
#41 | The system has rebooted without cleanly shutting down first
6+
#1074 | The system has been shutdown properly by a user or process
7+
#1076 | Follows after EventLog.Id ID 6008 and means that the first user with shutdown privileges logged on to the server after an unexpected restart or shutdown and specified the cause
8+
#6005 | The EventLog.Id Log service was started. Indicates the system startup
9+
#6006 | The EventLog.Id Log service was stopped. Indicates the proper system shutdown
10+
#6008 | The previous system shutdown was unexpected
11+
#6009 | The operating system version detected at the system startup
12+
#6013 | The system uptime in seconds
1313

1414
[int32]$WarningUptime = $args[0] #Uptime in total hours. Example, if you want 3 days enter 72
1515
[int32]$CriticalUptime = $args[1] #Uptime in total hours.
16-
[int32]$MaxEventAge = $args[2] #In total hours. Don't look back more than X hours in the event log
16+
[int32]$MaxEventAge = $args[2] #Uptime in total hours. Don't look back more than X hours in the event log
1717

1818
#-----------------
1919

2020
#Validate input
2121
if ($Error.Count -gt 0) {
2222
$LASTEXITCODE = 3
2323
Clear-Host
24-
Write-Output 'UNKNOWN: Only use Int32 numbers for the arguments'
24+
Write-Output 'UNKNOWN: Use only Int32 numbers for the arguments'
2525
exit $LASTEXITCODE
2626
}
2727

@@ -81,25 +81,25 @@ $EventsReformat = foreach ($EventLog in $EventsFiltered) {
8181

8282
#Get counts of event level types
8383
$CriticalCount = ($EventsReformat | Where-Object -Property Level -EQ 'Critical')
84-
if (($null -ne $CriticalCount) -and $null -eq $CriticalCount.Count) {
84+
if (($null -ne $CriticalCount) -and ($null -eq $CriticalCount.Count)) {
8585
$CriticalCount = 1
8686
} else {
8787
$CriticalCount = $CriticalCount.Count
8888
}
8989
$ErrorCount = ($EventsReformat | Where-Object -Property Level -EQ 'Error')
90-
if (($null -ne $ErrorCount) -and $null -eq $ErrorCount.Count) {
90+
if (($null -ne $ErrorCount) -and ($null -eq $ErrorCount.Count)) {
9191
$ErrorCount = 1
9292
} else {
9393
$ErrorCount = $ErrorCount.Count
9494
}
9595
$WarningCount = ($EventsReformat | Where-Object -Property Level -EQ 'Warning')
96-
if (($null -ne $WarningCount) -and $null -eq $WarningCount.Count) {
96+
if (($null -ne $WarningCount) -and ($null -eq $WarningCount.Count)) {
9797
$WarningCount = 1
9898
} else {
9999
$WarningCount = $WarningCount.Count
100100
}
101101
$InfoCount = ($EventsReformat | Where-Object -Property Level -EQ 'Information')
102-
if (($null -ne $InfoCount) -and $null -eq $InfoCount.Count) {
102+
if (($null -ne $InfoCount) -and ($null -eq $InfoCount.Count)) {
103103
$InfoCount = 1
104104
} else {
105105
$InfoCount = $InfoCount.Count
@@ -149,7 +149,8 @@ if ($LASTEXITCODE -eq 0) {
149149
Write-Output "Warning trigger: $WarningUptime hours"
150150
Write-Output "Critical trigger: $CriticalUptime hours"
151151
Write-Output "Max event age: $MaxEventAge hours"
152-
if ($EventsReformat.Count -gt 0) {
152+
153+
if ($Null -ne $EventsReformat) {
153154
Write-Output '
154155
=====
155156
Events

0 commit comments

Comments
 (0)