how to trap exchange exception in powershell ? RRS feed

  • Question

  • 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 
        + PSComputerName        : mbx1.domain.local

    I see exception type eq 


    and i try handle this type via

    Get-Recipient aaaa -ErrorAction stop -DomainController dc0
    catch [SuitabilityDirectoryException]{ 
    Write-Debug "dc do not work"
    # 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 [ ... ] ?

    Saturday, March 28, 2015 6:13 AM

All replies

  • Have you tried using the FullName for the Type eg

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



    Monday, March 30, 2015 3:04 AM