Powershell script to check HDD's

For anyone who has a home server running windows you can use this little script via scheduled tasks (daily, weekly, or on an actual event of hdd failure, your choice) to check your hard drive health. It will only email you IF it detects a hard drive as unhealthy. I made this script for a few Thecus Nas servers we have at remote sites. (Windows Storage Server 2012 R2)

[code]$healthstatus = Get-PhysicalDisk | Where-Object { $_.HealthStatus -ne ‘Healthy’ }
if ($healthstatus -ne $null)
$smtpServer = “mailserver.com#change this to suit your needs
$smtpFrom = "nas@mailserver.com" #change this to suit your needs
$smtpTo = “flea@mailserver.co.za” #change this to suit your needs
$messageSubject = “NAS HDD Status Report” #change this to suit your needs

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true

$style = “BODY{font-family: Arial; font-size: 10pt;}”
$style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
$style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
$style = $style + “TD{border: 1px solid black; padding: 5px; }”
$style = $style + “”

$message.Body = Get-PhysicalDisk | Select-Object FriendlyName,OperationalStatus,HealthStatus | ConvertTo-Html -Head $style

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)


The corresponding email will display as follows (except the healthy will be listed as warning or error)

Thanks Flea! Useful script to have! Been having quite regular hard drive failures on my rig - suspect overheating … 5 drives stacked in standard tower… #notrecommended :wink:

1 Like