Powershell script to create event source

Writing entries to application event log is a fairly common routine, and one of the thing to note is that the event source might not already exist and the user account under which your code runs might not have the necessary permissions to create them, which is completely acceptable and in fact, recommended.

Thus, a common practice is to create the necessary event sources upfront during deployment. This can be done using the folloing powershell script:

$eventSources = @(

foreach($source in $eventSources) {
    write-host "Creating event source $source"
    if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false) {
        [System.Diagnostics.EventLog]::CreateEventSource($source, "Application")
		write-host -foregroundcolor green "Event source $source created" 
        write-host -foregroundcolor yellow "Warning: Event source $source already exists" 

Posted on October 14, 2011, in Scripting and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: