none
Powershell Catch code never runs RRS feed

  • Question

  • I have some code which is being used to generate a report on the permissions assigned to non mailbox owners for a set of mailboxes in a csv file. I'm trying to introduce some level of error handling for when the mailbox doesn't exist on the Exchange environment (company is in the middle of a migration to O365). When the code runs, it throws an error message if it can't find the mailbox but never runs the catch code.

     try{  
     $mailbox=get-mailbox $_.mailbox -erroraction stop

    do some stuff

    }

    catch{

    write-host 'error thrown'

    }

    Is it simply the case that get-mailbox doesn't implement -erroraction properly (I was under the impression that all cmdlets had to implement the common parameters) or am I being stupid and missing something completely obvious (not beyond the bounds of possibility)

    Friday, January 6, 2017 9:00 AM

Answers