Use VBScript to monitor drive space

This tip was submitted to the SearchWinSystems.com tip exchange by member Mike Douglas. Please let other users know how useful it is by rating it below.

By using this script (possibly as a scheduled job), free space on systems or shares can be monitored and reported on via e-mail. It's usually a better idea to let your system inform you of space outages rather than your users.

  '** Basic drive usage monitoring script
  '** Usage:  cscript drivemon.vbs <TO: email> <FROM: email> 
<path1> <path2> <path3>... Dim fso, drv, s, drvPath, bBAD on error resume next bBAD = False Set objArgs = WScript.Arguments if (objArgs.Count > 2) then For i = 2 to objArgs.count - 1 drvPath = objArgs(i) Set fso = CreateObject("Scripting.FileSystemObject") Set drv = fso.GetDrive(fso.GetDriveName(drvPath)) eText = Err.Description if i < 1 then s = "Drive " & UCase(drvPath) & " - " else s = s & "Drive " & UCase(drvPath) & " - " end if s = s & drv.VolumeName s = s & vbcrlf x=int(drv.Freespace) y=int(drv.totalsize * .1) if eText > "" then s = s & eText & vbcrlf & vbcrlf eText = "" bBAD = True end if if x < y then s = s & "*** SPACE USAGE ALERT ***" & vbcrlf bBAD = True s = s & "Total Space: " & FormatNumber(drv.TotalSize / 1024, 0) s = s & " Kb" & vbcrlf s = s & "Free Space: " & FormatNumber(drv.FreeSpace / 1024, 0) s = s & " Kb" & vbcrlf & vbcrlf end if Next if bBAD then Set oEmail = CreateObject("CDO.Message") oEmail.From = objArgs(1) oEmail.To = objArgs(0) oEmail.Subject = "WARNING! Drive Monitor Report - " & now() oEmail.TextBody = s oEmail.Send Set oEmail = Nothing end if else wscript.echo "DriveMon.vbs - Email a report of drive usage on any accessible path." & vbcrlf & vbcrlf & "Usage: cscript drivemon.vbs <TO: email> <FROM: email>
<path1> <path2> <path3>..." end if

Do you have comments on this tip? Let us know.

This was first published in February 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.