The code to perform these two space checks is below, with the output file being generated in comma-delimited CSV format. When we use this, we need to first set a few configuration items in the first section.
- outputFile : Enter the path and file name of the output report.
- i : The number of items you wish to check; in the example, the number is 4 (2 drives and 2 folders)
- arrayList(x, y) : These are the details of each drive/folder you wish to check…
The code is as follows:
option explicit dim outputFile, arrayList, fso, obj, fl, j, drivepath, driveName, status, msg '''''''Config'''''''''' ' Where do you want to output the results to? outputFile = "checkSpace.log" ' How many drives do you want to check for free space? const i = 4 redim arrayList(i,5) 'Please do not touch this line. ' List the server drives you want to check for free space or folders to check for space usage ' Each set has 5 values: ' a. D=drive, F=folder ' b. server hostname ' c. admin share drive letter (applicable for type D only) ' d. warning level in gb ' e. alarm level in gb ' f. common name of this share arrayList(0,0) = "D" arrayList(0,1) = "web1" arrayList(0,2) = "c" arrayList(0,3) = 10 arrayList(0,4) = 5 arrayList(0,5) = "Windows 2003 web server, C-drive" arrayList(1,0) = "D" arrayList(1,1) = "exch2" arrayList(1,2) = "d" arrayList(1,3) = 200 arrayList(1,4) = 100 arrayList(1,5) = "Windows 2003 Exchange server, D-drive" arrayList(2,0) = "F" arrayList(2,1) = "\fileserverpublicfileShare1" arrayList(2,2) = "" arrayList(2,3) = 1 arrayList(2,4) = 2 arrayList(2,5) = "File share 1" arrayList(3,0) = "F" arrayList(3,1) = "\fileserverpublicfileShare2" arrayList(3,2) = "" arrayList(3,3) = 100 arrayList(3,4) = 200 arrayList(3,5) = "File share 2" '''''''End Config''''''''' set fso = CreateObject("Scripting.FileSystemObject") set fl = fso.CreateTextFile(outputFile, true) fl.writeline("""Item"",""Status"",""Message""") j = 0 do while j <= i-1 if arrayList(j,0) = "D" then drivepath = "\\" & arrayList(j,1) & "\" & arrayList(j,2) & "$" set obj = fso.GetDrive(fso.GetDriveName(drivepath)) elseif arrayList(j,0) = "F" then drivepath = arrayList(j,1) set obj = fso.GetFolder(drivepath) else ' shouldn't really get in here... end if driveName = arrayList(j,5) if arrayList(j,0) = "D" then if round(obj.FreeSpace/1024/1024/1024) < arrayList(j,4) then status = "alarm" msg = drivepath & " (" & driveName & ") only has " & round(obj.FreeSpace/1024/1024/1024) & "gb free" else if round(obj.FreeSpace/1024/1024/1024) < arrayList(j,3) then status = "warning" msg = drivepath & " (" & driveName & ") only has " & round(obj.FreeSpace/1024/1024/1024) & "gb free" else status = "ok" msg = drivepath & " (" & driveName & ") is ok with " & round(obj.FreeSpace/1024/1024/1024) & "gb free" end if end if elseif arrayList(j,0) = "F" then if round(obj.size/1024/1024/1024) > arrayList(j,4) then status = "alarm" msg = drivepath & " (" & driveName & ") has reached " & round(obj.size/1024/1024/1024) & "gb" elseif round(obj.size/1024/1024/1024) > arrayList(j,3) then status = "warning" msg = drivepath & " (" & driveName & ") has reached " & round(obj.size/1024/1024/1024) & "gb" else status = "ok" msg = drivepath & " (" & driveName & ") is ok at " & round(obj.size/1024/1024/1024) & "gb used" end if else status = "error" msg = "Configuration error" end if fl.writeline("""" & drivepath & """,""" & status & """,""" & msg & """") set obj = nothing j = j+1 loop set fl=nothing set fso=nothing
The output CSV file should look something like this.
"Item","Status","Message" "\\web1\c$","ok","\\web1\c$ (Windows 2003 web server, C-drive) is ok with 10gb free" "\\exch2\c$","alarm","\\exch2\c$ (Windows 2003 Exchange server, D-drive) only has 16gb free" "\\fileserver\public\fileShare1","warning","\\fileserver\public\fileShare1 (File share 1) has reached 2gb" "\\fileserver\public\fileShare2","ok","\\fileserver\public\fileShare2 (File sahre2) is ok at 91gb used"