WScript: Get Email when disk space low

Yesterday, Mick Genie come out a script to generate the free space from your computer, and it might useful for you for certain purpose.

However, I have think off if this is very inconvenience if you need to login to the computer for every time.

Hence I have come out another script to use IIS SMTP server to send an email to you when the disk space is low.

Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Disk Space Alert: ServerName”
objMessage.From = “Disk Space Alert<Disk Space Alert>”
objMessage.To = “[email protected]

Dim objShell, space_value, Result
Set objShell = Wscript.CreateObject(“WScript.Shell”)

Set DiskSet = GetObject(“winmgmts:{impersonationLevel=impersonate}”).ExecQuery (“select * from Win32_LogicalDisk where DriveType=3″)
For each Disk in DiskSet
If (Disk.Name=”D:”) Then
Disk.FreeSpace=Disk.FreeSpace/1024
Disk.FreeSpace=Disk.FreeSpace/1024
Disk.FreeSpace=Disk.FreeSpace/1024
Result = Disk.FreeSpace
End If
Next
space_value = Result
Wscript.echo space_value
if space_value < 30 then

objMessage.TextBody = “Server Disk Space Low, ” & space_value & ” GB”
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “127.0.0.0”
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objMessage.Configuration.Fields.Update
‘objMessage.Send

end if

You need to change the Subject, From, To, Email IP, and port only.

Note: This script tested only work with 32bits box, but not 64 bits box.  Save this file to anyname.vbs will do.

Windows Script object to get free space

Today, Mick Genie has come out same sample script to calculate the  free space from particular disk drive.

Below is the sample script as you may use the following script and save it to file.vbs.

Set DiskSpace = GetObject(“winmgmts:{impersonationLevel=impersonate}”).ExecQuery (“select * from Win32_LogicalDisk where DriveType=3″)
Dim Result
For each Disk in DiskSpace
If (Disk.Name=”D:”) Then
Disk.FreeSpace=Disk.FreeSpace/1024
Disk.FreeSpace=Disk.FreeSpace/1024
Disk.FreeSpace=Disk.FreeSpace/1024
Result = Disk.Name + ” ” + Disk.FreeSpace + ” GB”
End If
Next

WScript.Echo Result

With above script, you may change the drive with D: to E: , F: , etc and you will get the information from the drive specifically.