DrSeussFreak
Programmer
I have written a script that checks each drive letter on a server and if that drive letter has less than 10% free space left, it sends me an e-mail (per drive). My boss asked that it also send 1 e-mail a day if all the drives are ok. Below is my script, I need help to re-think the logic and was hoping for some ideas.
Thanks in advance.
Thanks in advance.
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
Dim dLetter
Dim fSpace
Dim tSize
Dim pFree
Dim vName
For Each objDrive in colDrives
dLetter = objDrive.DriveLetter
fSpace = objDrive.FreeSpace
tSize = objDrive.TotalSize
pFree = ((objDrive.FreeSpace / objDrive.TotalSize) * 100)
vName = objDrive.VolumeName
if pFree < "10" then
SendEmail "To goes here", "From Goes here", "Low Free Space Warning", _
dLetter & " (" & vName & ")" & " is low on space, and is currently at " & pFree & " space free."
' Wscript.Echo dLetter & " (" & vName & ")" & " is low on space, and is currently at " & pFree & " space free."
Else
' Wscript.Echo dLetter & " (" & vName & ")" & " is currently at " & pFree & " and so is OK!"
End If
Next
Sub SendEmail(strTo, strFrom, strSubject, strMsg)
schema = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/"[/URL]
SmtpServer = "SMTP Goes Here"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = strFrom
objEmail.To = strTo
objEmail.Subject = strSubject
objEmail.Textbody = strMsg
objEmail.Configuration.Fields.Item (schema & "sendusing") = 2
objEmail.Configuration.Fields.Item (schema & "smtpserver") = SmtpServer
objEmail.Configuration.Fields.Item (schema & "smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub