views:

42

answers:

1

Hello all,

I am using the below PowerShell function to parse event logs that have been saved locally from a remote machine. Unfortunately, I cannot for the life of me figure out how to dump out to another format instead of just to the console window.

When I insert an INTO statement into my SQL query I get the following error:

Exception calling "Execute" with "2" argument(s): "Cannot specify an INTO-entity when calling Execute() [The parameter is incorrect.]"

Any help is greatly appreciated.

    Function Parse-Event-Logs
{

$logtypes = "Application","System","Security"
foreach ($logtype in $logtypes)
{
$log_file = $LogsArchive + "\" + $folder + "\" + $logtype + ".evt"
$log_parser = new-object -comobject MSUtil.LogQuery
$log_type = new-object -comobject MSUtil.LogQuery.EventLogInputFormat
$log_type.resolvesids = $true
$log_type.fulltext = $true
$output_type = new-object -comobject MSUtil.LogQuery.NativeOutputFormat
$log_query = "SELECT * FROM $log_file  WHERE EventTypeName = 'Error event' OR EventTypeName = 'Warning event'"

$log_recs = $log_parser.execute($log_query,$log_type)
try{
do{
$lp_return = @{}
$log_entry = $log_recs.getrecord()

$lp_return.add("Index",$log_entry.getvalue("RecordNumber"))
$lp_return.add("EntryType",$log_entry.getvalue("EventTypeName"))
$lp_return.add("EventID",$log_entry.getvalue("EventID"))
$lp_return.add("Message",$log_entry.getvalue("Message"))
$lp_return.add("Category",$log_entry.getvalue("EventCategoryName"))
$lp_return.add("CategoryNumber",$log_entry.getvalue("EventCategory"))
$lp_return.add("ReplacementStrings",$log_entry.getvalue("Strings"))
$lp_return.add("Source",$log_entry.getvalue("SourceName"))
$lp_return.add("TimeGenerated",$log_entry.getvalue("TimeGenerated"))
$lp_return.add("TimeWritten",$log_entry.getvalue("TimeWritten"))
$lp_return.add("UserName",$log_entry.getvalue("SID"))
$lp_return | new-hashobject

$log_recs.movenext()
} while ($log_recs.atend() -eq $false)
}

Catch {Write-Host "Event log is empty"}
}
}
+1  A: 

OK, converting the comment to an answer. :-)

Use the ExecuteBatch method instead of the Execute method. ExecuteBatch allows for passing in input and output types.

Keith Hill