question

hansi4711 avatar image
0 Votes"
hansi4711 asked AlexZhu-MSFT commented

Write Event Log with Key in dataItems

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

windows-server-powershellmsc-operations-manager
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IIt seems this thread is not related to SCOM (msc-operations-manager-xxx), so I add powershell related tag. Thanks.

0 Votes 0 ·

1 Answer

CyrAz avatar image
1 Vote"
CyrAz answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.