문제

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