Created
May 23, 2015 14:37
-
-
Save rufflabs/dfebe419f929d6b3e14e to your computer and use it in GitHub Desktop.
Checks a Windows RAID status for at risk, and emails a notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Send-Notification { | |
param( | |
$Status | |
) | |
Send-MailMessage -To '' -From "" -SmtpServer ''` | |
-Subject "$($env:computername) $($Drive) RAID $($Status)" -Body "$($Drive)RAID status is: $($Status)" | |
} | |
# Drive letter to check | |
$Drive = 'F' | |
# Run DiskPart to find the status of the F drive | |
$DiskPart = "list volume" | diskpart | ? {$_ -match "\s$($Drive)\s"} | |
# Match will place the matching text into $matches variable | |
$DiskPart -match "\s\s(Healthy|OK|Rebuild|Failed|At Risk)" | |
# Trim the starting spaces, status will be used later on | |
$Status = $matches[0].TrimStart(' ') | |
switch -regex ($Status) { | |
"(OK|Healthy)" { | |
# All is good | |
} | |
"Rebuild" { | |
# Informational | |
} | |
"(Failed|At Risk)" { | |
# RAID has failed or has a failing disk, send an email notification | |
Send-Notification $Status | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment