Writing events with parameters using PowerShell

<!--[if lt IE 9]>


Comments (9)
  1. Ron Nishiguchi says:

    Hi Kevin,

    This is exactly what I was looking for. What parameter do I need in the powershell script to create an event level of Error?



    1. Kevin Holman says:

      Hi Ron,

      I updated the script to include capability for info, warning, or error events. Just uncomment which line you want.

      1. Ron Nishiguchi says:

        Hi Kevin,

        Perfect! Thanks,


  2. Jason Rydstrand says:

    Hello Kevin,

    Why does the event only show the data item in Event Viewer (General Properties), and yet if I go other events not created with this method, I see multiple data items in the general tab view?

    1. Kevin Holman says:

      I don’t know. But I kinda like it. This way I can input whatever variables I want in param 1 (which will show up in the event view) and then dump in all kinds of stuff in other params which will be hidden.

      1. Scott Banyas says:

        Is there a limitation on the number of params you may use? I appear to be getting “cutoff” after param4.

  3. Taksis Maksis says:


    Thanks for the script.
    Do you have any idea how to update Event’s XML metadata with attributes?
    E.g. attribute “Name” in this example


    See tag and “Name” attribute below:

    1. kberg says:

      I would LOVE to know this as well. Hoping it isn’t one of those Param or Message dlls that are used…

  4. Volkan Coskun says:

    Another Mr Holman saves the day again 🙂

    Just made a slight mod to create warning or error events on the fly

    function CreateParamEvent ($evtID,$type,[array]$params)

    If($type -eq ‘information’)
    $id = New-Object System.Diagnostics.EventInstance($evtID,1); #INFORMATION EVENT
    }Elseif($type -eq ‘warning’)
    $id = New-Object System.Diagnostics.EventInstance($evtID,1,2); #WARNING EVENT
    }Elseif($type -eq ‘error’)
    $id = New-Object System.Diagnostics.EventInstance($evtID,1,1); #ERROR EVENT
    }Else {write-warning “Please specify Event type information / warning / error “}
    $evtObject = New-Object System.Diagnostics.EventLog;
    $evtObject.Log = $evtlog;
    $evtObject.Source = $source;
    $evtObject.WriteEvent($id, [array]$params)

Comments are closed.

Skip to main content