Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Design, HTML And CSS Forums (http://www.go4expert.com/forums/web-design-forum/)
-   -   VBScript to check diskspace and threshold (http://www.go4expert.com/forums/vbscript-check-diskspace-threshold-t10633/)

marconi 15May2008 18:32

VBScript to check diskspace and threshold
 
I have 3 jobservers and a database server.

1) I need to first check the disk space.

2) then check if the free space on each drive is greater than 15% of the total disk space(which is the threshold value) and notify the user.
3) then shrink the databases.

I have written the following VBSCript, but it is giving a type mismatch error at Line 25, which is :- iThreshold=(15/100)*(Disksize)
------------------------------------------------------------------------------------------
Code:

Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FileSystemObject")
InputFile="Diskspace.txt"
Outputfile="Diskspacelist.csv"
SET ofile = oFSO.CreateTextFile(OutputFile)
SET ifile = iFSO.openTextFile(inputfile)
Const GBCONVERSION= 1048576000
ofile.writeline "Server,Drive,Disk Size,FreeSpace"

Do until ifile.AtEndOfLine
  Server = ifile.ReadLine               
  SET objWMIService = GetObject("winmgmts://" & Server)
  SET colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
      FOR EACH objLogicalDisk In colLogicalDisk
          IF objLogicalDisk.drivetype=3 then
                'Set variables
              'Set Disksize variable for size to be used later
                Disksize = FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB"
              Freespace = FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB"
              DeviceID = objLogicalDisk.DeviceID
                'Write to file using the variables
              ofile.writeline Server & "," & DeviceID & "," & Disksize & "," & Freespace
          END IF
            'Disksize was set in last IF statement
          iThreshold=(15/100)*(Disksize)
         
          If Int(freespace) < Int(iThreshold) THEN
          'freespace is less than the threshold so generate an alert
              wscript.Echo "Alert!"
                'Set variables to help read code better
              iThresh = FormatNumber(iThreshold,2,,TRUE) & " GB"
              iFreespace = FormatNumber(freespace,2,,TRUE) & " GB"
             
              strDescription = freespace & " is less than the specified threshold of " &_
              iThresh & ". Free space is " & iFreespace
             
              wscript.echo strDescription
          ELSE
          'folder size is OK
              WScript.Echo "The size of freespace is at least the threshold of " & iThreshold
          END IF
      Next             
  SET colLogicalDisk = NOTHING
  SET objWMIService = NOTHING
LOOP

-------------------------------------------------------------------------------------------

Can someone help me for rectifying the same.

Thanks a lot in advance.

Best Regards,
KiranKumar K.

pradeep 10Aug2009 11:19

Re: VBScript to check diskspace and threshold
 
Code: VBSCript

Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FileSystemObject")
InputFile="Diskspace.txt"
Outputfile="Diskspacelist.csv"
SET ofile = oFSO.CreateTextFile(OutputFile)
SET ifile = iFSO.openTextFile(inputfile)
Const GBCONVERSION= 1048576000
ofile.writeline "Server,Drive,Disk Size,FreeSpace"

Do until ifile.AtEndOfLine
   Server = ifile.ReadLine                 
   SET objWMIService = GetObject("winmgmts://" & Server)
   SET colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
       FOR EACH objLogicalDisk In colLogicalDisk
            Dim iThreshold
            Dim DiskSpaceSize
           IF objLogicalDisk.drivetype=3 then
                'Set variables
               'Set Disksize variable for size to be used later
                Disksize = FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB"
                DiskSpaceSize = objLogicalDisk.size
               Freespace = FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB"
               DeviceID = objLogicalDisk.DeviceID
                'Write to file using the variables
               ofile.writeline Server & "," & DeviceID & "," & Disksize & "," & Freespace
           END IF
            'Disksize was set in last IF statement
           iThreshold=(15/100)*(Disksize)
           
           If Int(freespace) < Int(iThreshold) THEN
           'freespace is less than the threshold so generate an alert
               wscript.Echo "Alert!"
                'Set variables to help read code better
               iThresh = FormatNumber(iThreshold,2,,TRUE) & " GB"
               iFreespace = FormatNumber(freespace,2,,TRUE) & " GB"
               
               strDescription = freespace & " is less than the specified threshold of " &_
               iThresh & ". Free space is " & iFreespace
               
               wscript.echo strDescription
           ELSE
           'folder size is OK
               WScript.Echo "The size of freespace is at least the threshold of " & iThreshold
           END IF
       Next             
   SET colLogicalDisk = NOTHING
   SET objWMIService = NOTHING
Loop



All times are GMT +5.5. The time now is 10:44.