Donald
Mon Aug 16 01:25:49 CDT 2004
This is what I came up with if anybody is interested,.
Its doing what i want allthough I cant breakup the .Message string returned.
I just copied bits and pieces from wscript.chm.
Option Explicit
Dim dtmStartDate, dtmEndDate, DateToCheck, strComputer
Dim objWMIService, colEvents, objEvent, sMessageStringCat, sheader
Dim CONVERT_TO_LOCAL_TIME, iCounter
'Application Variables
Dim sEmailFrom, sEmailTo, iEmailPort, sConEmailMonitor
sEmailFrom = "xxx@netspace.net.au"
sEmailTo = "xxx@netspace.net.au"
sConEmailMonitor = "xxxx@netspace.net.au"
strComputer = "servernamegoeshere"
iEmailPort = 25
iCounter = 0
sheader = String(55, "_")
CONVERT_TO_LOCAL_TIME = True
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date - 1
dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & _
strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent
Where LogFile='Security' AND (TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "') AND
(EventCode='529') ")
For Each objEvent In colEvents
iCounter = iCounter + 1
sMessageStringCat = sMessageStringCat & vbCrLf & sheader & vbCrLf &
vbTab & "Category: " & objEvent.Category & vbCrLf & vbTab & "Computer Name:
" & objEvent.ComputerName & vbCrLf & vbTab & "Message: " & objEvent.Message
Next
Set colEvents = Nothing
Set objWMIService = Nothing
If iCounter > 0 Then
SendEmailNotification "Email remote login security report from " &
UCase(strComputer), "Sent: " & FormatDateTime(Now) & vbCrLf & _
"This is an automated security report from " &
UCase(strComputer) & vbCrLf & _
"The below list is all FAILED remote logins to " & strComputer &
"By Windows Terminal Services " & vbCrLf & sMessageStringCat
End If
WScript.Quit
Function SendEmailNotification(TheSubJect, TheBody)
'******************************************************
'*** Send the message Using CDOSYS Win2k & Win2003 ****
'******************************************************
On Error Resume Next
' CDO mail object
Dim sch, cdoConfig, cdoMessage, sError
sch = "
http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(sch & "sendusing") = 2
cdoConfig.Fields.Item(sch & "smtpserverport") = iEmailPort
cdoConfig.Fields.Item(sch & "smtpserver") = strComputer
cdoConfig.Fields.Update
Set cdoMessage = CreateObject("CDO.Message")
Set cdoMessage.Configuration = cdoConfig
cdoMessage.From = sEmailFrom
cdoMessage.To = sEmailTo
cdoMessage.BCC = sConEmailMonitor
cdoMessage.Subject = TheSubJect
cdoMessage.TextBody = TheBody
'
cdoMessage.item("
http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").value
= 1 ' use clear text authenticate
'
cdoMessage.item("
http://schemas.microsoft.com/cdo/configuration/sendpassword").value
="mypassword"
'
cdoMessage.item("
http://schemas.microsoft.com/cdo/configuration/sendusername").value
="yourusername"
cdoMessage.Fields.Item("urn:schemas:mailheader:X-MSMail-Priority") =
"High"
cdoMessage.Fields.Item("urn:schemas:mailheader:X-Priority") = 2
cdoMessage.Fields.Item("urn:schemas:mailheader:Keywords") = "COKESHOP"
cdoMessage.Fields.Item("urn:schemas:mailheader:Sensitivity") =
"Company-Confidential"
cdoMessage.Fields.Item("urn:schemas:mailheader:X-Message-Flag") = "Do
not Forward"
cdoMessage.Fields.Update
cdoMessage.Send
Set cdoMessage = Nothing
Set cdoConfig = Nothing
If Err.Number <> 0 Then
sError = Err.Description
End If
On Error GoTo 0
End Function
"Donald Grover" <dgrover@assoft.com.au> wrote in message
news:uuLUnoxgEHA.3264@tk2msftngp13.phx.gbl...
> Im looking for a script that will read the Security Event Log on a w2k3
> server from the previous day and email to an email address.
> I can't seem to get it the qry to return both the previous days Successful
> / failed logins along with the date qry.
> Does anyone know of a script or can point me in the right direction
> Regards
> Don Grover
> dgrover@assoft.com.au
>
>
>