Back to Resources

Level Verified

Windows Monitor - Check SMART Disk Script

Created by

Level

Type

Script

Category

Maintenance

Platforms
WindowsApple iOSLinux

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.

Description

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.

Script

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}

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

FAQ

  • Does this script attempt any repairs on its own?
    No, it strictly checks disk health status and exits with an alert if issues are found. Use a separate repair script or automation if you want to attempt repairs.
  • What versions of Windows are supported?
    It relies on Get-PhysicalDisk, which is available on Windows 8.1/Server 2012 and later. Test compatibility in your environment.
  • Can I use this script to monitor external USB drives?
    Yes, if they appear under Get-PhysicalDisk. However, some external drives may have limited SMART reporting.
  • What happens if no disks are flagged as unhealthy?
    The script exits with a success code (0), indicating no immediate hardware concerns.
  • Is it safe to run this script on production servers?
    Reading SMART data is non-intrusive, but always test thoroughly to ensure compatibility with your specific environment.

Included with this Script:

Below is a list of what you can expect to find when importing this Script.

Script details:

The following data and settings will be imported with your script.

Script Name

Windows Monitor - SMART Disk Check

Description

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.

Language

PowerShell

Timeout (In Seconds)

100

Run As

Local system

Import into Level

Related resources

Explore more automations, scripts, and policies to further enhance your IT operations.

View all resources