Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event log as .csv

Status
Not open for further replies.

ipeca

IS-IT--Management
Jan 11, 2007
17
0
0
US
I'm trying to write a script that will save all of my event logs for me on a weekly basis. I have pieced together enough that I have a working script. However, I can't firgure out how to save the log file in a .csv format. Yes, saving in the .evt format would work, boss want's it in .csv....I don't know why.

Anyway, can anyone point in the direction I need to go?

Thanks

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup)}!\\" & _
        strComputer & "\root\cimv2")
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay


Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='Security'")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup,security)}!\\" & _
        strComputer & "\root\cimv2")

For Each objLogfile in colLogFiles
    errBackupLog = objLogFile.BackupEventLog("C:\Documents and Settings\macneill\My Documents\test\sec" & strBackupName & ".evt")
    If errBackupLog <> 0 Then        
        Wscript.Echo "The security event log could not be backed up."
    End If
Next
 
>I can't firgure out how to save the log file in a .csv format.
You can do it by writing out data parcel one-by-one per your own specification of csv. Otherwise, use some utility as suggested. That is what vbs can do until ms decides one day some method should be added to the class for alternative backup format.

If you want to want to have thing done auto by some script naitive method, you can look into powershell. It provisions with two cmdlets: get-eventlog:
and export-csv:
Connect the cmdlets one after the other with the pipe would get the backup output csv done.
 
Well no wonder I couldn't figure out how to do it from VBS. Thanks for the help....time to dream up an alternative solution.
 
But LogParser is both a utility and an ActiveX DLL that you can automate from within a WSH script. It will probably be able to do far more than what you need, and is intended for just such a purpose as you describe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top