Skip to content

Instantly share code, notes, and snippets.

@rufflabs
Created May 23, 2015 14:37
Show Gist options
  • Save rufflabs/dfebe419f929d6b3e14e to your computer and use it in GitHub Desktop.
Save rufflabs/dfebe419f929d6b3e14e to your computer and use it in GitHub Desktop.
Checks a Windows RAID status for at risk, and emails a notification
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