SHARE
Facebook X Pinterest WhatsApp

DTS Package for Reporting Low Disk Space

Jul 7, 2008


This VBscript code will check for low disk space on the local SQL Server. Schedule the package to run once a day, and let the job report to you by e-mail when a drive runs low on free space.

The script will check all disks except for the C: drive and will trigger an alert to be sent when the available disk space on any drive falls below 20% remaining. The code uses the WMI object library which comes with Windows 2000 and XP. WMI can also be installed on NT.

Author: Lennart Gerdvall

Function Main()
	REM WHAT IT DOES FOR YOU:
	REM This code will check for low disk space on the local SQL Server.
	REM Schedule the package to run once a day and let the job report to
	REM you by e-mail when it fails. The code below checks all disks but
	REM the C-disk and fails when disk space is below 20% remaining.
	
	REM HOW TO INSTALL IT:
	REM Create a DTS package with the VB cript code below.
	REM Set up a connection to the local server with Windows Authenication.
	REM The Windows user running the package must be admin on the machine being checked.
	
	REM OTHER REQUIREMENTS:
	REM The package requires Windows Management Instrumentation (WMI), which is
	REM included in Windows 2000 and later. If you have Windows 95/98/NT 4.0, install
	REM the WMI core library (wmicore.exe).
	REM More information - http://msdn.microsoft.com/downloads/sdks/wmi/default.asp 

	DIM DiskSet
	DIM myDisk, test
	
	myDisk = ""
	test = 0
	
  Set DiskSet = GetObject("winmgmts:{impersonationLevel=Delegate}").ExecQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
	
	For Each Disk In DiskSet
		if disk.name <> "C:" then
			test = (Disk.FreeSpace / Disk.Size)
			If test <= 0.20 then
				myDisk = myDisk + Disk.Name
			End If
		end if
	Next
	
	If myDisk <> "" Then 
		REM Yes, there are disks with LOW SPACE
	             Main = DTSTaskExecResult_Failure
	Else			 
		REM No, there no are disks with LOW SPACE
		Main = DTSTaskExecResult_Success
	End If
End Function

Back to Database Journal Home

Recommended for you...

What Backups Do I Have?
Gregory Larsen
May 12, 2021
Improving the Performance of a Table Variable using Optimizer Hint RECOMPILE
Gregory Larsen
Apr 1, 2021
TYPE Definition Change in Oracle 21c
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.