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) ------------------------------------------------------------------------------------------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.
VBScript to check diskspace and threshold
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
VBScript to check diskspace and threshold
Hi, Thanks for your response. I have changed 2 lines of my code to take care that I multiply a number with a number and not a string, as shown below in bold. Request you to please let me know your comments. ----------------------------------------------------------------------------------------------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 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 DS = FormatNumber(Disksize,2,,TRUE) 'Disksize was set in last IF statement and DS variable also set iThreshold=(15/100)*(DS) If Int(freespace) < Int(iThreshold) THEN 'freespace is less than the threshold so generate an alert wscript.Echo "Alert!" 'Set variables 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 ----------------------------------------------------------------------------------------------
Regards, Marconi
Regards, Marconi