I have defined some windows events which I register to event viewer with an event manifest file. But when I get the events from my provider by invoking powershell command
(Get-WinEvent -ListProvider MyProvider).Events
I noticed that the task values (System.Diagnostics.Eventing.Reader.EventTask) were parsed into a wrong data type. For example, the task value of an event is defined as 65534 in the event manifest file, but powershell parsed it to -2. Consequently, I cannot publish this windows event in powershell, i.e. when I invoke
New-WinEvent -ProviderName MyProvider -Id MyEventId -Payload MyPayload
I get the following exception:
New-WinEvent : Non negative number is required. Parameter name: task + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-WinEvent], ArgumentOutOfRangeException + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.PowerShell.Commands.NewWinEventCommand
Because the task associted with MyEventId is parsed to a negative number. Yet I have seen this windows event successfully logged in event viewer with the correct task value.
Is this a bug in powershell? Does anyone have a suggestion to get around this problem so that I can publish this windows event from powershell?
Edit:
According to EventLogRecord.Task, task value can be anything between 0 and 65519, so 65534 is not a valid task value anyway. But I have another task with value 65493, which lies apparently in the range, but it is still parsed to -43. The same exception mentioned above is thrown when I try to publish a windows event associated with this task.