Exchange exception handling

Hello guys,

I wrote a script that adds Users to Distribution groups.
i was trying to add Error handling to my script but the problem is i can’t seem to get the actual typename of the exceptions, i always get

TypeName: System.Management.Automation.Runspaces.RemotingErrorRecord
I can see the exception name in the error for ex:


But i understand i need the full name of those exceptions,i can’t find a way to get it from this exchange remote session
How can i get that ?

okay i think i found a way to do it
with -match operator and it’s working

if($_.categoryinfo.reason -match "MemberAlreadyExistsException") {do something }
            elseif($_.CategoryInfo.Reason -match "WriteErrorException") do something}
            elseif($_.CategoryInfo.Reason -match "ManagementObjectNotFoundException") {do something}
            elseif($_.CategoryInfo.Reason -match "ADObjectAlreadyExistsException") {do something}
            else{$email.status = do something else}