Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript sending email twice for multiple drives on Server 1

Status
Not open for further replies.

davy2k

Technical User
Mar 18, 2007
69
JP
Hi All,
I wrote a script to monitor Free disk space if any of the drives gets to say 20GB on a server with multiple disks, but the issue is it sends the email for each drive...

is there a better way to make all results go out in a single email, rather than multiple.

Here is a sample of the script:

' List Available Disk Space

Const HARD_DISK = 3

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

If CInt(objDisk.FreeSpace/1024/1024/1024) < 20 Then

For Each objDisk in colDisks
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "helpdesk@fusionsystems.co.jp"
objEmail.To = "pius.oshinuga@fusionsystems.co.jp"
objEmail.Subject = "RED ALERT: DISK SPACE RUNNING LOW!!"
objEmail.TextBody = "Drive: "& vbTab & objDisk.DeviceID & vbTab & "Free Space: "& vbTab & CInt(objDisk.Size/1024/1024/1024) & "GB" & vbTab & "Total Size: "& vbTab & CInt(objDisk.FreeSpace/1024/1024/1024) & "GB"
objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = "tok-exch"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send

'Wscript.Echo "Drive: "& vbTab & objDisk.DeviceID & vbTab & "Free Space: "& vbTab & CInt(objDisk.FreeSpace/1024/1024/1024) & "GB" & vbTab & "Total Size: "& vbTab & CInt(objDisk.Size/1024/1024/1024) & "GB"

Next
End If

Thank you for your assistance
 
The idea is to send email only after all data are collected.
[tt]
' List Available Disk Space

Const HARD_DISK = 3

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

dim s
s=""
For Each objDisk in colDisks
If CInt(objDisk.FreeSpace/1024/1024/1024) < 20 Then
if len(s)<>0 then s=s & vbcrlf
s=s & "Drive: "& vbTab & objDisk.DeviceID & vbTab & "Free Space: "& vbTab & CInt(objDisk.Size/1024/1024/1024) & "GB" & vbTab & "Total Size: "& vbTab & CInt(objDisk.FreeSpace/1024/1024/1024) & "GB"
'Wscript.Echo "Drive: "& vbTab & objDisk.DeviceID & vbTab & "Free Space: "& vbTab & CInt(objDisk.FreeSpace/1024/1024/1024) & "GB" & vbTab & "Total Size: "& vbTab & CInt(objDisk.Size/1024/1024/1024) & "GB"
End If
Next
if len(s)<>0 then sendMail(s)

sub sendMail(sbody)
dim objEmail
Set objEmail = CreateObject("CDO.Message")
with objEmail
.From = "[ignore]helpdesk@fusionsystems.co.jp[/ignore]"
.To = "[ignore]pius.oshinuga@fusionsystems.co.jp[/ignore]"
.Subject = "RED ALERT: DISK SPACE RUNNING LOW!!"
.TextBody = sbody
.Configuration.Fields.Item _
("[ignore][/ignore]") = 2
.Configuration.Fields.Item _
("[ignore][/ignore]") = "tok-exch"
.Configuration.Fields.Item _
("[ignore][/ignore]") = 25
.Configuration.Fields.Update
.Send
end with
end sub
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top