Submitted By: Chris Harrod

Given a list of computers, this script alerts you when free disk space falls below a specified limit.

Visual Basic
Edit|Remove
' Freespace script
' POC chris.harrod@gmail.com

on error resume next

Set objNet = WScript.CreateObject( "WScript.Network" )

Const CONVERSION_FACTOR = 1048576

strFilename = "c:\scripts\workstations.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objTextStream = objFSO.OpenTextFile(strFilename, 1)

Do Until objTextStream.AtEndOfStream

    strComputer = objTextStream.ReadLine
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
    FreeMegaBytes = objLogicalDisk.Freespace / CONVERSION_FACTOR

    If FreeMegaBytes < 1000 Then
        Wscript.Echo strComputer & " is below is below 1GB.  Only " & Int(FreeMegaBytes) & _
            "MB remaining"
    End if
    Err.Clear
Loop