WhoKilledKenny
MIS
Barney thanks for your last post.
Here is the issue I am now having and I am puzzled. When executing the code below and usting the strComputer = "." Everything works great on the local machine.
When I try to do the same query on a remote server by changing strComputer = "Servername" I do not get any output from wscript.echo. My dubbuger states no error when running the script. I am a domain admin so I don't believe I am running into any type of permissions issue. Please look at the code and respond with any suggestions. Thanks again everyone...
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date - 7
dtmEndDate.SetVarDate Date, True
dtmStartDate.SetVarDate DateToCheck, True
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For Each objEvent in colEvents
If objEvent.Type ="error" Then
WScript.Echo "Event Type: " & objEvent.Type
WScript.Echo "Source: " & objEvent.SourceName
WScript.Echo "User: " & objEvent.User
WScript.Echo "Event Date and Time: " & objEvent.TimeGenerated
Wscript.Echo "Description: " & objEvent.Message
End If
Next
Here is the issue I am now having and I am puzzled. When executing the code below and usting the strComputer = "." Everything works great on the local machine.
When I try to do the same query on a remote server by changing strComputer = "Servername" I do not get any output from wscript.echo. My dubbuger states no error when running the script. I am a domain admin so I don't believe I am running into any type of permissions issue. Please look at the code and respond with any suggestions. Thanks again everyone...
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date - 7
dtmEndDate.SetVarDate Date, True
dtmStartDate.SetVarDate DateToCheck, True
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For Each objEvent in colEvents
If objEvent.Type ="error" Then
WScript.Echo "Event Type: " & objEvent.Type
WScript.Echo "Source: " & objEvent.SourceName
WScript.Echo "User: " & objEvent.User
WScript.Echo "Event Date and Time: " & objEvent.TimeGenerated
Wscript.Echo "Description: " & objEvent.Message
End If
Next