Common parameter -ErrorAction not working with Get-NAVol?


I noticed that the common parameter -ErrorAction might not work as expected with the cmdlet Get-NaVol. I tried the following to handle errors caused by wrong volume names passed to my script via parameter:

$NAVol = Get-NaVol $Volume -ErrorAction SilentlyContinue -ErrorVariable err
if ($err) { Write-Host "Error: Volume $Volume not found!" -ForegroundColor red ; exit 1 }

When I pass a wrong volume name to my script, an error PowerShell exception message is shown regardless of the value SilentlyContinue which is to suppress these error messages.

Is it a bug or am I doing anything wrong?

Tested with Data Ontap PowerShell Toolkit 1.3

Re: Common parameter -ErrorAction not working with Get-NAVol?

ErrorAction only applies to non-terminating errors.  Most of the getter cmdlets in the Toolkit throw terminating errors if something fails.  We may very well reconsider that convention, but you can always do this:

PS C:\> try { Get-NaVol asdf } catch { write-host "Try again" }
Try again

Re: Common parameter -ErrorAction not working with Get-NAVol?

Understood, but does this comply with PowerShell conventions? A "get-item blabla -ErrorAction SilentlyContinue" supresses the error message and I don't see a big difference between the inention of both cmdlet (get-item and get-navol)

Re: Common parameter -ErrorAction not working with Get-NAVol?

Understood and agreed.  This is logged for proper consideration in the next release.  Thanks for the feedback!

Re: Common parameter -ErrorAction not working with Get-NAVol?

I'd like to bump the priority of this issue up. The PowerShell APIs are implemented haphazardly like this example, and it makes scripting a real pain.


$var1 = get-nasnapshot -name 'somevol' -snapname 'doesnotexist'

This snapshot doesn't exist, but the command doesn't complain. $var1 will be $null. This is good for testing the existence of a snapshot!

$var2 = get-navol -name 'doesnotexist'

This volume doesn't exist. The API pukes. Presumably $var2 will be $null, but there is no way to keep the exception from printing on the screen. -ErrorAction would be pretty handy here.