how to trap exchange exception in powershell ?

Hi all!

i try write handling some types of exceptions for Get-Recipient cmdlet. How must i define exceptions in catch block?
i work with exchange server in powershell, not im ems.

look like..

if i try execute get-recipient with wrong domain controller i get:

Get-Recipient aaaa -ErrorAction stop -DomainController dc0

An Active Directory error 0x51 occurred when trying to check the suitability of server 'dc0'. Error: 'Active directory response: The LDAP server is unavailable.'
At C:\Users\gsv\Documents\WindowsPowerShell\Modules\ExchangeModule\ExchangeModule.psm1:25039 char:9
+         $steppablePipeline.End()
+         ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Recipient], SuitabilityDirectoryException
    + FullyQualifiedErrorId : [Server=mbx1,RequestId=27f70386-fd1d-4e33-8e10-beb3c9aadeb5,TimeStamp=28.03.2015 5:14:50] [FailureCategory=Cmdlet-SuitabilityDirectoryException] B41D026,Microsoft.Exchange.Manageme 
   Microsoft.Exchange.Management.RecipientTasks.GetRecipient
    + PSComputerName        : mbx1.domain.local

I see exception type eq 

SuitabilityDirectoryException

and i try handle this type via

try{
Get-Recipient aaaa -ErrorAction stop -DomainController dc0
}
catch [SuitabilityDirectoryException]{ 
Write-Debug "dc do not work"
}
catch{
# something
}
and get error:

Unable to find type [SuitabilityDirectoryException]. Make sure that the assembly that contains this type is loaded.


For Active Directory cmdlets i use assembly name Microsoft.ActiveDirectory.Management and it's work.
For exchange i try to use or Microsoft.Exchange Microsoft.Exchange.Management or Microsoft.Exchange.Management.RecipientTasks but it's not work.

how should i write exception name in catch [ ... ] ?

March 28th, 2015 2:16am

Have you tried using the FullName for the Type eg

catch [Microsoft.Exchange.Data.Directory.SuitabilityDirectoryException]{

}

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
March 29th, 2015 11:05pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics