Is it possible to check if a powershell command succeeded or not?
Example:
Set-CASMailbox -Identity:blocks.5 -OWAMailboxPolicy "DoNotExists"
caused the error:
Outlook Web App mailbox policy "DoNotExists" wasn't found. Make sure you typed the policy name correctly.
+ CategoryInfo : NotSpecified: (0:Int32) [Set-CASMailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : 9C5D12D1,Microsoft.Exchange.Management.RecipientTasks.SetCASMailbox
I think that it should be possible to fetch the FullyQualifiedErrorId so I tried the following:
$test = Set-CASMailbox -Identity:blocks.5 -OWAMailboxPolicy "DoNotExists"
But it looks like the error isn´t transferred into the test variable.
So what is the correct way here to perform something like:
$test = Set-CASMailbox -Identity:blocks.5 -OWAMailboxPolicy "DoNotExists"
if ($test -eq "error")
{
Write-Host "The Set-CASMailbox command failed"
}
else
{
Write-Host "The Set-CASMailbox command completed correctly"
}