Problem overview
Hard drive failures can lead to data corruption, downtime, and costly disruptions. Many IT professionals struggle to predict disk failures before they happen, lacking insight into critical hardware health metrics. By automatically monitoring SMART data, this script helps ensure potential disk issues are quickly spotted and addressed.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-monitor-check-smart-disk
#>
# Checks local disks for health status
$DiskState = Get-PhysicalDisk | Where-Object {$_.HealthStatus -ne 'Healthy'}
if ($DiskState){
$DiskState | out-host
write-host "ALERT: Disk failure predicted!"
exit 1
} This script queries each physical disk on a Windows system via PowerShell’s Get-PhysicalDisk command. It then checks for any disks with a health status that isn’t Healthy, raising an alert and exiting with a nonzero status if issues are detected. This enables quick detection of early warning signs, allowing you to configure or run follow-up automations in Level to attempt repairs or schedule part replacements before failures occur.
Use cases
- Preventing unexpected hardware failures by actively monitoring disk health
- Adding an extra layer of protection for critical data storage on workstation or server environments
- Integrating with Level’s alerting to expedite response times
- Triggering an automated repair sequence or replacement procedures
Recommendations
- Configure a script-based monitor in Level to run this script a set frequency, checking disk health regularly
- For larger environments, consider frequent interval checks on critical servers, while scheduling routine checks for workstations
- Test in a non-production environment to confirm that the script works with your specific disk configurations
- If a disk is flagged, follow up with hardware diagnostics tools and consider running a repair automation (e.g., CHKDSK) through Level
- Ensure backup routines are current to mitigate data loss risks