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

Status : 

 


1
1
Sign in
to vote
ID 787271 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 5/20/2013 2:23:15 PM
Access Restriction Public

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.
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
}