VBScript-check dskspace; threshold DB shrinking.
Posted: Tue May 06, 2008 11:11 pm
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 not serving the purpose.
Request you to please provide me with the correct inputs/script.
-------------------------------------------------------------------------------------
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 ofile.writeline Server & "," & objLogicalDisk.DeviceID &_ "," & FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB, " &_ FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB, " end if Next Loop
iThreshold=(15/100)*(size)iSize=freespace
If Int(iSize) < Int(iThreshold) Then'free space is less than the threshold so generate an alertwscript.Echo "Alert!"strDescription=objLogicalDisk.freespace & " is less than the specified threshold of " &_FormatNumber(iThreshold,2,,True) & " GB. Free space is " &_FormatNumber(iSize,2,,True) & " GB"wscript.echo strDescriptionElse'folder size is OKWScript.Echo "The size of " &freespace & " (" & iSize &_ ") is at least the threshold of " & iThresholdEnd If
-------------------------------------------------------------------------------------------
Thanks a lot in advance.
Marconi.
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 not serving the purpose.
Request you to please provide me with the correct inputs/script.
-------------------------------------------------------------------------------------
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 ofile.writeline Server & "," & objLogicalDisk.DeviceID &_ "," & FormatNumber(objLogicalDisk.size/GBCONVERSION,2) & "GB, " &_ FormatNumber(objLogicalDisk.freespace/GBCONVERSION,2) & "GB, " end if Next Loop
iThreshold=(15/100)*(size)iSize=freespace
If Int(iSize) < Int(iThreshold) Then'free space is less than the threshold so generate an alertwscript.Echo "Alert!"strDescription=objLogicalDisk.freespace & " is less than the specified threshold of " &_FormatNumber(iThreshold,2,,True) & " GB. Free space is " &_FormatNumber(iSize,2,,True) & " GB"wscript.echo strDescriptionElse'folder size is OKWScript.Echo "The size of " &freespace & " (" & iSize &_ ") is at least the threshold of " & iThresholdEnd If
-------------------------------------------------------------------------------------------
Thanks a lot in advance.
Marconi.