I'm sure this has been answered a million times on a million sites, but for whatever reason I can't find what I'm looking for. Here's my code,
This scripts works great except for the last part. I want message boxes to pop up if a server has less than 10% free space. Problem is, in my output file % free is a string. How do I convert that to a number so that I can use '< 10' to check free space? I've tried CSng, CDbl, etc with no luck.
Thanks in advance.
-If it ain't broke, break it and make it better.
Code:
Set iFSO = CreateObject("Scripting.FilesyStemObject")
Set oFSO = CreateObject("Scripting.FilesyStemObject")
InputFile="\\bhmopfs3\sys\support\Diskspace\serverlist.txt"
Outputfile="\\bhmopfs3\sys\support\diskspace\Freespacelist_" + cstr(Month(now()))+"_"+cstr(day(now()))+".csv"
Set ofile = ofso.createTextFile(OutputFile, True)
Set ifile = iFSO.OpenTextFile(inputfile)
Const MBCONVERSION= 1048576
ofile.writeline "Computer,Drive,Disk Size (MB),FreeSpace (MB),% Free"
Do until ifile.AtEndOfLine
computer = ifile.ReadLine
Set objWMIService = GetObject("winmgmts://" & Computer)
Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk")
For Each objLogicalDisk In colLogicalDisk
if objLogicalDisk.drivetype=3 Then
ofile.writeline Computer & "," & objLogicalDisk.DeviceID &_
"," & objLogicalDisk.size/MBCONVERSION & "," &_
objLogicalDisk.freespace/MBCONVERSION & "," &_
FormatNumber((objLogicalDisk.freespace/MBCONVERSION)/(objLogicalDisk.size/MBCONVERSION), 3)
end If
Next
Loop
MsgBox("Disk space report generated.")
ofile.Close
ifile.Close
Set Input = iFSO.Opentextfile(Outputfile, "1", True)
Do While Input.AtEndOfStream <> True
arrServerInfo = Input.Readline
if not isempty(arrServerInfo) Then
arrServerDetail = Split(arrServerInfo, ",")
ServerName = arrServerDetail(0)
ServerDrive = arrServerDetail(1)
ServerTotalSpace = arrServerDetail(2)
ServerFreeSpace = arrServerDetail(3)
PercentFree = arrServerDetail(4)
If PercentFree > "10" Then
MsgBox("Drive " & ServerDrive & " on server " & ServerName & " is low on space.")
End If
End If
Loop
This scripts works great except for the last part. I want message boxes to pop up if a server has less than 10% free space. Problem is, in my output file % free is a string. How do I convert that to a number so that I can use '< 10' to check free space? I've tried CSng, CDbl, etc with no luck.
Thanks in advance.
-If it ain't broke, break it and make it better.