سؤال

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