-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisk_Events_Detect.ps1
More file actions
35 lines (27 loc) · 1.25 KB
/
Disk_Events_Detect.ps1
File metadata and controls
35 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Define the log name and event IDs for disk errors and warnings
$eventLogName = 'System'
$errorEventID = 7 # The event ID for disk errors
$warningEventID = 52 # The event ID for disk warnings
# Get the latest disk error and warning events from the specified log
$latestErrorEvent = Get-WinEvent -LogName $eventLogName -MaxEvents 1 | Where-Object { $_.Id -eq $errorEventID }
$latestWarningEvent = Get-WinEvent -LogName $eventLogName -MaxEvents 1 | Where-Object { $_.Id -eq $warningEventID }
# Check if there is a recent disk error or warning event
if ($latestErrorEvent -or $latestWarningEvent) {
# There is a recent disk error or warning event
Write-Host "Disk issues detected:"
if ($latestErrorEvent) {
Write-Host "Latest Disk Error Event:"
$latestErrorEvent | Format-Table -AutoSize
}
if ($latestWarningEvent) {
Write-Host "Latest Disk Warning Event:"
$latestWarningEvent | Format-Table -AutoSize
}
# Return a custom exit code to indicate an issue (e.g., 1)
exit 1
} else {
# No recent disk error or warning event
Write-Host "No recent disk issues detected."
# Return a success exit code to indicate no issues (e.g., 0)
exit 0
}