Pages

Wednesday, June 29, 2011

WMI Script to get data from Eventviewer

The below script will give you the details from EventViewer for sourcetype "Application" where there is an Error


strComputer = "."

Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NTLogEvent Where Logfile ='Application' And Type= 'Error' ",,48)


For Each objItem in colItems
     Msgbox (objItem.TimeGenerated)

     Msgbox (objItem.Message)
     Msgbox(objItem.SourceName)
     Msgbox(objItem.Type)
     Msgbox(objItem.User)
     Msgbox(objItem.Category)
     MsgboxobjItem.ComputerName)
Next

No comments:

Post a Comment