Powershell script to monitor mount points in Windows and e-mail an alert

Simple script inspired by this blog post.

This script will read a servers.txt file located in the same directory as the script, check each server listed (one per line, use the servers FQDN) for mount points, see how much free space is available, compare it to a minimum amount you set and then e-mail an alert if below the minimum amount.

Should work on Windows Server 2008 and newer. Might work on Server 2003 but I haven’t tested it.

# Script to monitor storage on disk mount points. Orignally created for Exchange.
# Created by: Eric Schewe
# Created on: 2016-01-06
# Original Source: http://www.powershellneedfulthings.com/?p=36
# Create a server.txt file in the same directory as the script with a list of servers in it

# How low in GB do you want to let free space get before notification?
# You can go up to two decimal spaces if you want
$lowSpace = 10.00

# E-mail stuff
# Multiple e-mail addresses should be in this format "<[email protected]>, <[email protected]>"
$to = ""
$from = "[email protected]n"
$smtpServer = "smtp.localdomain"

# Injest Server list, one server FQDN per line
# You may need to have the full path to the servers.txt here if you're running this as a scheduled task
$servers = (Get-Content "servers.txt")

# Check each server
foreach ($server in $servers)

    # First check if the server is up
    if ((Test-Connection -quiet $server) -eq $true) {

        # Get all the volumes on the server with out a drive letter
        $volumes = Get-WmiObject -computer $server win32_volume | Where-object {$_.DriveLetter -eq $null}

        # Check each volume found
        foreach ($volume in $volumes) {

            # Skip the System Reserved volume. It will always be low
            if ($volume.Label -ne "System Reserved") {

                # Do some math to convert bytes into GB, rounded and 2 decimal places
                if (([math]::round(($volume.FreeSpace / 1073741824),2)) -le $lowSpace) {

                    # Send an e-mail notification including low disk space setting, server fqdn and volume name
                    $subject = "Low disk space warning (below $($lowSpace)GB) - $($server) - $($volume.Label)"
                    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
                    $smtp.Send($from, $to, $subject, "")