Link to home
Start Free TrialLog in
Avatar of Brian S
Brian SFlag for United States of America

asked on

command line results for dcdiag and eventlogs

I'm preparing a script to parse looking for information from DC Diag and eventlogs on a Windows 2008 R2 server.

My question is this how can I via command line search for events in the eventlogs (e.g. EventIDs) and what is the path to dcdiag? I can see that I can just run it via the command line without a path, but if I want to script it I need a path.

any help would be appreaciated.
ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brian S

ASKER

Wow that was quick. I'll give that a go.
Missed the date conversion
'On Error Resume Next

servername="."
Set objWMIService = GetObject("winmgmts:\\" & ServerName & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery("Select * from Win32_NTLogEvent Where EventCode=1079")

For Each objEvent In colLoggedEvents      
    WScript.Echo  objEvent.EventCode &","& WMIStringToDate(objEvent.TimeWritten)
Next    

'DCdiag Test
dcdiagout=""
Set objShell = CreateObject("Wscript.Shell")
dcocommand = "dcdiag /s:"& ServerName

Set objExec = objShell.Exec(dcoCommand) 

dcdiagout=objExec.StdOut.ReadAll()

WScript.Echo "dcdiag " & dcdiagout

Function WMIStringToDate(dtmDate)
    WMIStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

Open in new window