Skip to content

Instantly share code, notes, and snippets.

@Zer0xFF
Last active July 1, 2021 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zer0xFF/1f9764c4443121df69befa77bbf30baa to your computer and use it in GitHub Desktop.
Save Zer0xFF/1f9764c4443121df69befa77bbf30baa to your computer and use it in GitHub Desktop.
Disk Status Health Report (can be used with dynamic disks)
function Report-Disk
{
param (
$name,
$disks
)
$body = ($disks | Out-String)
$body = "$($name) $($body)"
Send-MailMessage -From 'ME <ME@ME.ie>' -To 'ME <ME@ME.ie>' -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