Prerequisites
Steps to reproduce
If you run Get-WinEvent -ListLog * | select -First 1 you will get a long stream of errors like this:
PS C:\> Get-WinEvent -ListLog * | select -First 1
LogMode MaximumSizeInBytes RecordCount LogName
------- ------------------ ----------- -------
Circular 15728640 3333 Windows PowerShell
Get-WinEvent: To access the 'Windows PowerShell' log start PowerShell with elevated user rights. Error: The pipeline has been stopped.
Get-WinEvent: To access the 'System' log start PowerShell with elevated user rights. Error: The pipeline has been stopped.
...
This is because Get-WinEvent is catching every exception here: https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs#L550 so the PipelineStoppedException doesn't get to bubble up and stop the pipeline like it should.
To fix this we should only catch the errors we expect from the underlying API (this would also help with the bad error message) or just filter out the PipelineStoppedException exception.
Expected behavior
The `PipelineStoppedException` is left uncaught so the pipeline can exit early without spamming errors.
Actual behavior
The `PipelineStoppedException` is caught and a bunch of errors are spammed to the console.
Error details
Environment data
Name Value
---- -----
PSVersion 7.6.1
PSEdition Core
GitCommitId 7.6.1
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Prerequisites
Steps to reproduce
If you run
Get-WinEvent -ListLog * | select -First 1you will get a long stream of errors like this:This is because
Get-WinEventis catching every exception here: https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs#L550 so thePipelineStoppedExceptiondoesn't get to bubble up and stop the pipeline like it should.To fix this we should only catch the errors we expect from the underlying API (this would also help with the bad error message) or just filter out the
PipelineStoppedExceptionexception.Expected behavior
The `PipelineStoppedException` is left uncaught so the pipeline can exit early without spamming errors.Actual behavior
The `PipelineStoppedException` is caught and a bunch of errors are spammed to the console.Error details
Environment data
Visuals
No response