VB Script: DiskSpace Monitoring

When i needed a script to check multiple servers for disk usage, i found this script: http://gallery.technet.microsoft.com/ScriptCenter/en-us/cc8176ab-348b-4152-b9a3-25b6ad950d3e

Download it here: [wpdm_file id=”17″], or see the code:

'******************************************************************************
'* Provides data from disks from a list of servers (servers.txt)              *
'* Created by Nag Pal and Modify by Martin Scaine                             *
'* The original script don't manage error,                                    *
'* so if you can't connect to a server it will repeat the data from last.     *
'* Also I include the date on the name of the report file and on it header.   *
'* It can be usefull if you need to check it every day                        *
'******************************************************************************

On Error Resume Next
Const ForAppending = 8
Const HARD_DISK = 3
Const ForReading = 1

'Var declaration
dtmDay = Day(Date)
dtmMonth = Month(Date)
dtmYear = Year(Date)
dtmDate = CDate(dtmYear & "-" & dtmMonth & "-" & dtmDay)

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the server list
Set SrvList = objFSO.OpenTextFile("Servers.txt", ForReading)

'Create a result file
If dtmday < 10 and dtmMonth >9 then
Set ReportFile = objFSO.OpenTextFile ("Srv_Disk_Space_" & dtmYear & "-" & dtmMonth & "-0" & dtmDay & ".html", ForAppending, True)
End If
If dtmday > 9 and dtmMonth < 10 then
Set ReportFile = objFSO.OpenTextFile ("Srv_Disk_Space_" & dtmYear & "-0" & dtmMonth & "-" & dtmDay & ".html", ForAppending, True)
End If
If dtmday < 10 and dtmMonth < 10 then Set ReportFile = objFSO.OpenTextFile ("Srv_Disk_Space_" & dtmYear & "-0" & dtmMonth & "-0" & dtmDay & ".html", ForAppending, True) End If If dtmday > 9 and dtmMonth >9 then
Set ReportFile = objFSO.OpenTextFile ("Srv_Disk_Space_" & dtmYear & "-" & dtmMonth & "-" & dtmDay & ".html", ForAppending, True)
End If
i = 0

'Inicializar HTML
ReportFile.writeline("")
ReportFile.writeline("")
ReportFile.writeline("")
ReportFile.writeline("")
ReportFile.writeline("")
ReportFile.writeline("
-->")
ReportFile.writeline("")
ReportFile.writeline("")

ReportFile.writeline("

“) ReportFile.writeline(“”) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(”

“) ReportFile.writeline(“Server Space Disk Report ” & dtmdate & ““) ReportFile.writeline(“
")

'Server name declaration
Do Until SrvList.AtEndOfStream
	StrComputer = SrvList.Readline

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

	If Err.Number <> 0 Then
		ReportFile.writeline("

“) ReportFile.writeline(“”) ReportFile.writeline(” “) ReportFile.writeline(” “) Err.Clear Else ReportFile.writeline(”

Error – ” & StrComputer & ” – Error

“) ReportFile.writeline(“”) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(“”) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(” “) ‘Data recolection For Each objDisk in colDisks ‘Var init TotSpace=0 FrSpace=0 FrPercent=0 UsSpace=0 Drv=”Error” VolName=”Error” ‘Var charge TotSpace=Round(((objDisk.Size)/1073741824),2) FrSpace=Round(objDisk.FreeSpace/1073741824,2) FrPercent=Round((FrSpace / TotSpace)*100,0) UsSpace=Round((TotSpace – FrSpace),2) Drv=objDisk.DeviceID VolName=objDisk.DeviceID ‘Lnt=Len(VolName) ‘If Len(VolName) = 3 then If FrPercent > 20 Then ReportFile.WriteLine ” ” ElseIf FrPercent < 10 Then ReportFile.WriteLine ” ” Else ReportFile.WriteLine ” ” End If ‘Else ‘End If Next End If ReportFile.writeline(“”) ReportFile.writeline(” “) ReportFile.writeline(” “) ReportFile.writeline(”

” & StrComputer & “
Drive / Mount Total Capacity (in GB) Used Capacity (in GB) Free Space (in GB) Freespace %
” & Drv & “ ” & TotSpace & “ ” & UsSpace & “ ” & FrSpace & “ ” & FrPercent & “%” &”
” & Drv & “ ” & TotSpace & “ ” & UsSpace & “ ” & FrSpace & “ ” & FrPercent & “%” &”
” & Drv & “ ” & TotSpace & “ ” & UsSpace & “ ” & FrSpace & “ ” & FrPercent & “%” &”
")
Loop
ReportFile.WriteLine ""

2 thoughts on “VB Script: DiskSpace Monitoring

  1. This script is failing to work on Microsoft Clustered servers (Windows 2003). Let me know if you have any additions to rectify this.

Leave a Reply

Your email address will not be published. Required fields are marked *