Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-Expression ignores the common -ErrorAction parameter #19734

Open
5 tasks done
mklement0 opened this issue Jun 2, 2023 · 2 comments
Open
5 tasks done

Invoke-Expression ignores the common -ErrorAction parameter #19734

mklement0 opened this issue Jun 2, 2023 · 2 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@mklement0
Copy link
Contributor

mklement0 commented Jun 2, 2023

Prerequisites

Steps to reproduce

Invoke-Expression unexpectedly ignores the common -ErrorAction parameter when applied to itself (as opposed to the string being evaluated happening to contain a command with -ErrorAction).

# !! Error still prints.
Invoke-Expression 'Get-Item NoSuchFile' -ErrorAction Ignore

The suboptimal workaround is to use 2>$null, though that is the equivalent of -ErrorAction SilentlyContinue, not Ignore.

Also note:

Expected behavior

No output (the non-terminating error should be ignored).

Actual behavior

The non-terminating error prints.

Error details

No response

Environment data

PowerShell 7.4.0-preview.3

Visuals

No response

@mklement0 mklement0 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 2, 2023
@237dmitry
Copy link

I think errors rise after executing expression:

iex "gi noexist"
iex "gi noexist -ea 0"

@mklement0
Copy link
Contributor Author

Yes, -ErrorAction inside the string to be evaluated works, but that's not the point of this issue - I've updated the initial post to make that clear.

@kilasuit kilasuit added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

No branches or pull requests

3 participants