Get-Winevent - Execution with only -MaxEvents parameters specified
When executing the Get-Winevent cmdlet with only the -MaxEvents parameter specified the cmdlet ends up in an infinite loop spewing errors:
Get-WinEvent -MaxEvents 1
Get-WinEvent : The data is invalid
At line:1 char:9
+ $null = Get-WinEvent -MaxEvents 1
+ CategoryInfo : NotSpecified: (:) [Get-WinEvent], EventLogInvalidDataException
+ FullyQualifiedErrorId : The data is invalid,Microsoft.PowerShell.Commands.GetWinEventCommand
I reproduced this error on PowerShell 5.1 and 4.0 on multiple systems. The behavior I expected was to receive the most recent event from any of the event logs. I feel this error could be prevented by using proper parameter validation.
Not critical, but definitely annoying. I’ve filed a bug internally.