PowerShell: Try/Catch does not work in version 5 with Exchange/Azure PS functions

Here is what I am doing

try{

Get-Mailbox -Identity ed@contoso.com -erroraction stop

Write-host “User exists”

}catch{

Write-host “User does not exist”

Continue

}

It works fine in PS 2,3,4 until I get to PS 5 where the erroraction will not work. The user does not exist, but it displays the error and moves on. I have tried $ErrorActionPreference=”stop” just before my try but it made no difference. Perhaps its time to move away from the try/catch? Anyway here is the work around I did and perhaps this is what i will have to do in place of try/catch.

$chkmbx=$null #Empty the checker variable before use else you may get some false results

$chkmbx=Get-Mailbox -Identity ed@contoso.com -erroraction silentlycontinue

if ($chkmbx){Write-host “User exists”

}

if (!($chkmbx)){

Write-host “User does not exist”

Continue

}