Powershell 5 ErrorAction Stop

Welcome Forums General PowerShell Q&A Powershell 5 ErrorAction Stop

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 2 months ago.

  • Author
    Posts
  • #29103

    Participant
    Points: 1
    Rank: Member

    I have a script I've been using for a while in PS 4, but after upgrading to Windows 10 "-ErrorAction Stop" is not working with try/catch.

    This is a basic part of the code that is not working
    try {
    $mbx = Get-Mailbox $UserID -ErrorAction Stop
    .....
    }
    catch {
    $mbx = Get-RemoteMailbox $UserID
    .....
    }

    The error is showing as if there was no EA action defined. If I replace Stop for SilentlyContinue, it works as expected, but I need the Stop switch so I can work with try/catch.

    Any ideas?

  • #29109

    Member
    Points: 0
    Rank: Member

    I haven't used the Exchange module much personally, but I've seen comments about -ErrorAction being flaky when used with implicit remoting. People seem to be able to work around it by setting $ErrorActionPreference, instead of using the -ErrorAction parameter. (This is annoying, and I'd call it a bug in PowerShell, but that's where things stand at the moment.)

  • #29116

    Participant
    Points: 1
    Rank: Member

    Strange thing is it works just fine in every computer I have with PS version 4 (we use the same script in at least 6 different machines with Win7 or 2012), but on my laptop with PS version 5 and Win10 it won't.

The topic ‘Powershell 5 ErrorAction Stop’ is closed to new replies.