Trying to log errors with mailbox move

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 10 months ago.

  • Author
    Posts
  • #6493

    by Scott762 at 2012-11-02 12:44:02

    I'm trying to log the errors with an Exchange 2010 mailbox move request, with no luck. I've tried a few formats, either I get a blank error log (first attempt), or the script stops after the first error despite a return or continue.
    First, it's turning off updating address by policy, second turning off Activesync in Ex2003, then lastly creating the move request.

    Close, but yet so far. Thanks in advance!!!

    First attempt :
    # Add Quest ActiveRoles AD snap-in
    Add-PSSnapin Quest.ActiveRoles.ADManagement
    # Add Exchange 2010 Snap-in
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

    $Userstodatabase = import-csv USERS.csv

    foreach ($Record in $Userstodatabase)
    {
    $users = $record.user
    $database = $record.database
    Set-Mailbox -identity $users -EmailAddressPolicyEnabled $False
    Set-QADUser -identity $users -ObjectAttributes @{msExchOmaAdminWirelessEnable = 7}
    New-MoveRequest –identity $users –TargetDatabase “$Database” -AllowLargeItems 2>> "ERRORS.txt"
    }

    Alternate attempt:
    # Add Quest ActiveRoles AD snap-in
    Add-PSSnapin Quest.ActiveRoles.ADManagement
    # Add Exchange 2010 Snap-in
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

    $Userstodatabase = import-csv USERS.csv
    Try {
    foreach ($Record in $Userstodatabase)
    {
    $users = $record.user
    $database = $record.database
    Set-Mailbox -identity $users -EmailAddressPolicyEnabled $False
    Set-QADUser -identity $users -ObjectAttributes @{msExchOmaAdminWirelessEnable = 7}
    New-MoveRequest –identity $users –TargetDatabase “$Database” -AllowLargeItems
    }
    }

    Catch [Exception] {
    $users + "," + $_.Exception.Message | Out-File Errors.txt -Append
    Continue
    }

    by coderaven at 2012-11-05 03:28:48

    I would use the Alternative method with a try/catch block. In addition to what you tried, on The New-MoveRequest command add the -ErrorAction switch with "Stop" as the option like so

    New-MoveRequest –identity $users –TargetDatabase “$Database” -AllowLargeItems -ErrorAction Stop

    by Scott762 at 2012-11-05 06:21:03

    Thanks Allan, but I wouldn't want it to stop. What I would like is the error to be logged, so it would be simple to look for which move requests failed to rectify.

    by coderaven at 2012-11-05 09:06:39

    In the Try/Catch it will go to Catch if you put in the "Stop" and continue the loop. The stop just tell it that something has happened -> go to catch. See DonJ CPT Nugget here

You must be logged in to reply to this topic.