2009年6月8日 星期一

exchange使用空間監控通知

If Weekday(Date) <2 OR Weekday(Date)>6 Then
Wscript.Quit
End If

ExChangeServer = "kido.idv.tw"
ExtremeSize = 50*1024

Set objService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & ExChangeServer & "\root\MicrosoftExchangeV2")

Set colSettings = objService.ExecQuery("Select * from Exchange_Mailbox")
On Error Resume Next
For Each obj in colSettings
If Instr(UCase(obj.MailboxDisplayName),"(NTCTX)") And CLng(obj.Size) > CLng(ExtremeSize) Then
Result = Result & "" & vbCrLf &_
"" & obj.MailboxDisplayName & "" & vbCrLf &_
"" & obj.Size & "" & vbCrLf &_
"" & obj.TotalItems & "" & vbCrLf &_
""
End If
Next
If Result <> "" Then
Mail "Mailbox healthy check!",RebuildMsg(Result)
End If
Function RebuildMsg(msg)
msg = "" &_
"" & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"" &_
msg
msg = msg & "
" & "Emp Name" & "" & "Mail Size (KB)" & "" & "Mail Count" & "
"
RebuildMsg = msg
End Function

Sub Mail(Subject,Content)
MailFrom = "kido@kido.idv.tw"
MailTo = "kido@kido.idv.tw"
If Len(Content) = 0 Then
Exit Sub
End If
Set objEmail = CreateObject("CDO.Message")
objEmail.From = MailFrom
objEmail.To = MailTo
objEmail.Cc = MailCC
objEmail.Subject = Subject
objEmail.HTMLBody = Content
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ExChangeServer
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub

除此方法外~~上可利用powershell來作~~功能相同~~都是利用WMI去截取Exchange的值

沒有留言: