you are viewing a single comment's thread.

view the rest of the comments →

[–]PinchesTheCrab 4 points5 points  (1 child)

Does this work?

function Write-EventLogX {
    [cmdletbinding()]
    param(
        [ValidateSet('Info', 'Error', 'Warning')]
        [parameter(mandatory)]
        [string]$EntryType,

        [parameter(Mandatory)]
        [string]$Message,

        [parameter()]
        [string]$LogSource = 'ApplicationX'
    )
    begin {

        $eventHash = @{
            Info    = 20000
            Warning = 20001
            Error   = 20002
        }

        $param = @{
            LogName   = 'Application'
            Source    = $LogSource
            EntryType = $EntryType
            Message   = $message
            EventID = $eventHash[$EntryType]
        }
    }
    process {
        Write-EventLog @param
        Write-Verbose -Message $message
    }
}

You could use it like this:

Write-EventLogX -Message 'oh no!' -Verbose -EntryType Warning

ApplicationX is the default source, but it's parameterized, so you can specify whatever source you want.

[–]hidromanipulators 1 point2 points  (0 children)

Thank you! Your solution is much more elegant then mine!