Hello!
I want to create Event-Log entries with 4 data-items. I have found the following example of Kevin Holman:
#Load the event source to the log if not already loaded. This will fail if the event source is already assigned to a different log.
if ([System.Diagnostics.EventLog]::SourceExists($EvtSource) -eq $false) {
[System.Diagnostics.EventLog]::CreateEventSource($EvtSource, $EvtLog)
}
switch ($EvtType) {
"Information" { $id = New-Object System.Diagnostics.EventInstance($EvtID,$EvtID,4) }
"Warning" { $id = New-Object System.Diagnostics.EventInstance($EvtID,$EvtID,2) }
"Error" { $id = New-Object System.Diagnostics.EventInstance($EvtID,$EvtID,1) }
Default { $id = New-Object System.Diagnostics.EventInstance($EvtID,$EvtID,4) }
}
$evtObject = New-Object System.Diagnostics.EventLog;
$evtObject.Log = $EvtLog;
$evtObject.Source = $EvtSource;
$evtObject.WriteEvent($id, @($param1,$param2,$param3,$param4))
This will create an entry like this:
<EventData>
<Data>Key Value</Data>
</EventData>
But I need the Key in Parameter:
<EventData>
<Data Name="Key">Value</Data>
</EventData>
Is this possible?
rg
Hansi