Back to Resources
Level
Script
Maintenance
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 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.
1<#
2This resource is provided as a convenience for Level users. We cannot
3guarantee it will work in all environments. Please test before deploying
4to your production environment. We welcome contributions to our community
5library
6
7Level Library
8https://level.io/library/script-windows-monitor-check-smart-disk
9#>
10
11# Checks local disks for health status
12$DiskState = Get-PhysicalDisk | Where-Object {$_.HealthStatus -ne 'Healthy'}
13if ($DiskState){
14 $DiskState | out-host
15 write-host "ALERT: Disk failure predicted!"
16 exit 1
17}
Windows Monitor - SMART Disk Check
This PowerShell script monitors the health status of all physical disks on a Windows system by querying disk information using the Get-PhysicalDisk cmdlet and filtering for any disks that don't have a "Healthy" status. If any unhealthy disks are detected, the script outputs detailed information about the problematic disk(s), displays an alert message warning of potential disk failure, and exits with error code 1, making it ideal for automated monitoring systems like Level.io that can trigger notifications based on exit codes.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.