Tuesday, January 19, 2010

SMTP Alerting in VBScript for Free Space

This particular piece of work takes the amount of Free Space on a given machine and sends an alert / SMTP message to the user. This allows the user to passively monitor the file consumption on a given server/machine.

Set objEmail = CreateObject("CDO.Message")
Dim iSpc, strComputer, objWMIService, strEmailDim fso, fsHandle, MyShell,LogFileName, colItems, objItemSet MyShell = CreateObject("Wscript.Shell")Set fso = Wscript.CreateObject("Scripting.FilesystemObject")strComputer = InputBox("Enter a Computer Name or IP Address:","Remote Computer Free Space Finder")LogFileName = MyShell.SpecialFolders("Desktop") & "\" & strComputer & "-" & "FreeSpace.txt"strEmail = InputBox("Enter an E-mail Address:","Enter E-mail")set fsHandle = fso.OpenTextFile (LogFileName,8,True)
fsHandle.Writeline Date
Set objWMIService = GetObject _( "winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery _("Select * From Win32_LogicalDisk Where DriveType = 3")

For Each objItem in colItems 'Retrieve free space & convert from uint64iSpc = cDbl(objItem.FreeSpace)

objEmail.From = "
ServerMonitor@local"objEmail.To = strEmailobjEmail.Subject = strComputer & " disk report" objEmail.Textbody = objItem.DeviceID & " has " & iSpc/1000000000 & " GB free"objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _ "smtp.google.com" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25objEmail.Configuration.Fields.UpdateobjEmail.Send

fsHandle.Writeline objItem.DeviceIDfsHandle.Writeline iSpc/1000000000 & " GB"
Next
Function FormatiSpc(intSpace) intSpace = intSpace/1024 intSpace = intSpace/1024 intSpace = intSpace/1024 intSpace= FormatNumber(intSpace,1) FormatiSpc = intSpaceend function
fsHandle.Writeblanklines 1fsHandle.closeset MyShell = Nothingset fso = Nothing

No comments:

Post a Comment

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...