VBScript-check dskspace; threshold DB shrinking.

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
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.
Locked
User avatar
marconi
Posts: 5
Joined: Tue May 06, 2008 10:33 pm

VBScript-check dskspace; threshold DB shrinking.

Post by marconi » 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.

User avatar
marconi
Posts: 5
Joined: Tue May 06, 2008 10:33 pm

VBScript-check dskspace; threshold DB shrinking.

Post by marconi » 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.

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

VBScript-check dskspace; threshold DB shrinking.

Post by donj » Tue May 06, 2008 11:36 pm

Please keep in mind that most of us aren't able to run your script since our environments differ from yours.

Can you tell us what error occurs, or what the script is supposed to do that it isn't doing? Exactly why is the script not serving its purpose?

Locked