Last active
July 1, 2021 14:46
-
-
Save Zer0xFF/1f9764c4443121df69befa77bbf30baa to your computer and use it in GitHub Desktop.
Disk Status Health Report (can be used with dynamic disks)
This file contains 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 Report-Disk | |
{ | |
param ( | |
$name, | |
$disks | |
) | |
$body = ($disks | Out-String) | |
$body = "$($name) $($body)" | |
Send-MailMessage -From 'ME <[email protected]>' -To 'ME <[email protected]>' -Subject 'Potential Disk Failure' -SmtpServer "smtp.gmail.com" -Body $body -Port 587 | |
} | |
function Is-Healthy | |
{ | |
param ( | |
$disks, | |
$count | |
) | |
if(($disks | measure).Count -ne $count) | |
{ | |
return [bool] 0 | |
} | |
foreach($disk in $disks) | |
{ | |
if($disk.HealthStatus -ne 'Healthy') | |
{ | |
return [bool] 0 | |
} | |
} | |
return [bool] 1 | |
} | |
$drives = "SERIALNUMBER1", ("DISKSERIAL1", "DISKSERIAL2"), "SERIALNUMBER2", | |
foreach($drive in $drives) | |
{ | |
$disks = Get-PhysicalDisk | Where-Object -Property SerialNumber -CIN $drive | |
$count = ($drive | measure).Count | |
if(-Not (Is-Healthy $disks $count)) | |
{ | |
Report-Disk $drive $disks | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment