PowerShell: Windows Storage Spaces (WSS) health check + email alerts

Someone asked me for a way to alert on Windows Storage Spaces (WSS) issues on their home NAS server. My answer was a very dissapointing "I don't know". In an enterpise we could use SNMP traps either from Windows or directly from the controller, and the chances are the controller software could alert you in multiple ways.

In a home enviroment setting up something that eats SNMP seems excessive, and how many of us have a dedicated storage controller in our home NAS.

Seems like we need a simple PowerShell soluton.

Now this is very rough and ready. I may revisit this, give it some extra features and put it into actual functions, make the output nice, but I may not. All that really matters is it does what he asked.

You will need to run this as a schedule tasl. Run it as often as you want to check the file system for issues. I would probably not make it any more frequent than every 5 minutes, and it will email constantly if there is an error. Like I said, it needs work.

$diskhealth = Get-StoragePool | select -ExpandProperty HealthStatus 
$diskstat =  Get-StoragePool | Select-Object FriendlyName, OperationalStatus, HealthStatus 

if ($diskhealth -ne "Healthy")
    $MailArgs = @{
    From       = 'User@yahoo.com'
    To         = 'mat@grumpy.tech'
    Subject    = 'Storage Spaces error'
    Body       = $diskstat
    SmtpServer = 'smtp.mail.yahoo.com' //change to whatever
    Port       = 587
    UseSsl     = $true
    Credential = New-Object pscredential'User@yahoo.com',$('Password' |ConvertTo-SecureString -AsPlainText -Force)

Send-MailMessage @MailArgs