get-mailbox WITH ErrorAction Stop does not catch error


I’m aware that you should use -ErrorAction Stop for non-terminating errors, so when catch didn’t work with get-mailbox it was the first thing I tried.

try { get-mailbox "bogus.user" -errorAction Stop } catch { write-host "It was caught" } 

I would expect that this code would write “It was caught” to the console but instead I get the regular error message “Object ‘bogus.user’ couldn’t be found”. I’ve also tried it without -ErrorAction Stop and have the same result.

What is different about get-mailbox? I use this type of try/catch in all of my modules and haven’t had this particular problem before.

I assume I’m missing something obvious, can anyone point it out?

Thank you,

submitted by /u/joshadm
[link] [comments]

Leave a Reply