Powershell Disk Health Check

Grentz

Fully [H]
Joined
May 5, 2006
Messages
17,273
Figured this might be useful to someone around here.

I am running Server 2012 and needed something to alert on issues with my Storage Space Mirrors and a RAID array. Windows has a health status that reads "OK" when everything is fine to its knowledge.

This is a powershell script that reads that status, then alerts to email if it senses that status as anything other than OK.

Code:
$WMI = Get-WMIObject -Computer localhost -Class Win32_DiskDrive
$body = "URGENT Disk Report `n`n"
$allclear = ""
ForEach ($Drive in $WMI){
    $body += $Drive.Caption + ": " + $Drive.Status + "`n"
    if ($Drive.Status -ne "OK") { $allclear = "N" }
    
}
$date = Get-Date
$body += "`nExecuted at " + $date  

if ($allclear -eq "N") {

$EmailFrom = "EMAIL ADDRESS"
$EmailTo = "EMAIL ADDRESS" 
$Subject = "ISSUE DETECTED"  
$SMTPServer = "smtp.gmail.com" 
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
$SMTPClient.EnableSsl = $true 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("USERNAME", "PASSWORD"); 
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}
else { Write-host "No Issues Detected" }
 
Back
Top