I have script that creates user accounts and establishes an e-mail address for those accounts. All 'create-commands' are surrounded by a try/catch block to catch errors and add a message to the output log. This works fine... except for the enable-mailbox command

try { 
    Enable-Maibox (.. parameters ...) 
}
catch {
    $errorsEncountered = $true
    Write-Output "Error establishing e-mail address for $($UserData.username)"
}

when the enable-mailbox command fails... the catch-part is skipped. Why is this? And how can I fix this?

有帮助吗?

解决方案

Non-termineting errors are not catched. Use '-ErrorAction Stop' to make the errors terminating errors.

Enable-Maibox (.. parameters ...) -ErrorAction Stop

其他提示

I could be wrong but "Enable-Maibox" looks mis-spelled.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top