Home Dashboard Directory Help
Search

PS v3 Get-Variable: -ErrorAction parameter is ignored for scope id error by johndog


Status: 

Active


1
1
Sign in
to vote
Type: Bug
ID: 787271
Opened: 5/20/2013 2:23:15 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description


Even if you pass in -ErrorAction ignore, get-variable always generates an error.

There doesn't appear to be a way to determine the number of active scopes without trial and error, and this problem complicates that approach.
Details
Sign in to post a comment.
Posted by David Wyatt on 6/12/2013 at 7:16 PM
ErrorAction only applies to non-terminating errors, and this one appears to be one of the situations where you get a terminating error instead. To intercept it, use a try-catch-finally block. In the Catch block, $_ refers to the ErrorRecord object for the terminating error; it also gets written to $error or your ErrorVariable before the catch block executes.

try
{
    Get-Variable -Scope 42
}
catch
{
    "Caught a terminating error: "
    $_ | Get-Member
}
Sign in to post a workaround.