New PowerShell Event Creator for Operations Manager 2007


Did you remember the Event Creator for MOM 2005 which was available in the Resource Kit? You could use this tool to create events for testing Management Packs. Event Creator enables you to choose event sources for the existing event logs that are currently registered. You can probably use this tool also for testing in your OpsMgr environment but why not use PowerShell?

You have at least installed PowerShell on you Management Server(s) so why not use PowerShell to create events for testing?

With some help from the PowerShell Guy I created a PowerShell script to create events in the eventlog.

# Description: Create Events in Application log
# Date: 03-05-2007
# Author: Stefan Stranger
# Explanation: If you only wish to write to the event log you must do two things. The first is to create or specify a Source. 
# The second is to call the WriteEntry method. The source would be your application name, by default, 
# if you create a source that is new then your log entry will be written to the Application Log. 
# To WriteEntry method does the actual writing to the Event Log.
# ev.WriteEntry(My event text, System.Diagnostics.EventLogEntryType.Information, myeventid)

#Check if user is admin
function get-Admin {
$ident = [Security.Principal.WindowsIdentity]::GetCurrent()

 foreach ( $groupIdent in $ident.Groups ) {
if ( $groupIdent.IsValidTargetType([Security.Principal.SecurityIdentifier]) ) {
$groupSid = $groupIdent.Translate([Security.Principal.SecurityIdentifier])
if ( $groupSid.IsWellKnown("AccountAdministratorSid") -or $groupSid.IsWellKnown("BuiltinAdministratorsSid")){
return $TRUE
return $FALSE

$Result = get-Admin

if ($Result -eq $FALSE) 
write-host "Better be an admin for this script."

function Write-EventLog { 
param ([string]$msg = $(read-host "Please enter a Event Description"), [string]$source = $(read-host "Please enter Event Source"), [string]$type = $(read-host "Please enter Event Type [Information, Warning, Error]"), [int]$eventid = $(read-host "Please enter EventID"))
# Create the source, if it does not already exist.
write-host "Source exists"

    # Check if Event Type is correct
switch ($type) 

"Information" {} 
"Warning" {} 
"Error" {} 
default {"Event type is invalid";exit}

    $log = New-Object System.Diagnostics.EventLog 

Write-Host "Event created"

Or you can download the PowerShell script from the PowerShell Code Repository.