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.by coderaven at 2012-11-05 03:28:48
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
}
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 soby Scott762 at 2012-11-05 06:21:03New-MoveRequest –identity $users –TargetDatabase “$Database†-AllowLargeItems -ErrorAction Stop
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