Hi!
Im wondering if anyone else had any problems catching specific errors from Exchange 2010 cmdlets? It seems like no matter what I do the only way to catch an error is by not specifying the error type.
Im guessing it has something to do with Exchange cmdlets using a remote session?
Example that works:
try
{Get-DistributionGroup -Identity 'DoNotExists' -ErrorAction Stop}
catch{ Do something }
But what I really want is to catch specifik errors for example:
Grop 'DoNotExists' returned 6F0E11E5,Microsoft.Exchange.Management.RecipientTasks.GetDistributionGroup
I guess I could always do something like this:
try {Get-DistributionGroup -Identity 'DoNotExists' -ErrorAction Stop}
catch
{
if ($_.Exception -Match "*Error message...*")
{
# Do something about it
}
}
But there must be a "correct" way to catch Exchange cmdlet error types?
I would really appreciate if someone could guide me in the right direction, thanks!