Check disk space and sent email .vbs


””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””’
‘This VBScript is compiled and modified by kerneled
’23 August 2010
””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””’

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” & strComputer & “rootcimv2″)
Set colDisks = objWMIService.ExecQuery _
(“Select * from Win32_LogicalDisk Where DeviceID = ‘C:’ or DeviceID = ‘D:’”) ‘Set drive to be check
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
gbFreeSpace = intFreeSpace / 1073741824
‘Wscript.Echo FormatPercent(pctFreeSpace)

If gbFreeSpace < 2 Then

Set objMessage = CreateObject(“CDO.Message”)

objMessage.Subject = “Server Low Disk Space “ & objDisk.DeviceID
objMessage.Sender = “Server13@edomain.it”
objMessage.To = “email@domain.it”
objMessage.TextBody = “Server Low Disk Space: “ & FormatNumber(gbFreeSpace,0) _
& “GB remaining. Check disk drives.” & vbcrlf _
& “Message automatically generated by EdScript.”

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “webmail.domain.it”

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 0

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “”

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “”

objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False

‘set the timeout to 60 seconds.
‘objMessage.Configuration.Fields.Item _
‘(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60

objMessage.Configuration.Fields.Update
objMessage.Send

‘Wscript.Echo “Message sent successfully.”

Else
‘Wscript.Echo “Enough Disk Space.”
End If
Next