# .SYNOPSIS # This is a wrapper script for bulk processing various MRS MoveRequest cmdlets. # # .DESCRIPTION # There are actually two independant scripts # First one: Executes "[New|Set|Resume|Remove]-MoveRequest" cmdlets by reading their parameter data from the passed CSV data. This will be used in XFR (cross forest relocation) work. # Second one: Injects move requests by reading the input from a given file # # Parameters for the first script: # # .PARAMETER Records # Cmdlet records data. Each record contains the cmdlet name and parameters # # .PARAMETER TenantName # Name of the tenant that is used in checking if the offline GLS override is specified for this tenant. For protection purposes. # # Common parameters: # # .PARAMETER LogFile # Log file name. Logs are written to the local machine where the script is actually executing. # If not specified, it will be created in ExchangeInstallFolder\logging\XFR folder # # .PARAMETER Test # If set to "True", performs the simulation only. # # Parameters of the second script: # # .PARAMETER $BatchName # Batchname of the injected moves # # .PARAMETER $InputFile # The file that contains the move injection data # # .PARAMETER IgnoreExcludedFromInitialProvisioning # Ignores the IsExcludedFromInitialProvisioning db flag # # # .EXAMPLE # # Given these sample CSV files: # Sample1: # Operation,Identity,RemoteHostName,RemoteOrganizationName,TargetDeliveryDomain,SkipMoving,InternalFlags,Remote,Protect,PreventCompletion,Confirm,CheckInitialProvisioningSetting,BadItemLimit,TargetDatabase,ArchiveTargetDatabase,SuspendWhenReadyToComplete,Priority,StartAfter,CompleteAfter,IgnoreRuleLimitErrors,LargeItemLimit,AllowLargeItems,BatchName,DoNotPreserveMailboxSignature,AcceptLargeDataLoss,ForceOffline # new-moverequest,test4@kc2.extest.microsoft.com,EXHV-7909.EXHV-7909dom.extest.microsoft.com,kc2.extest.microsoft.com,kc2.extest.microsoft.com,,"ConvertSourceToMeu,ResolveServer,UseTcp,CrossResourceForest,SkipProvisioningCheck",1,1,,,1,444,,,1,High,,,,,,,,, # new-moverequest,test2@kc2.extest.microsoft.com,EXHV-7909.EXHV-7909dom.extest.microsoft.com,kc2.extest.microsoft.com,kc2.extest.microsoft.com,,"ConvertSourceToMeu,ResolveServer,UseTcp,CrossResourceForest,SkipProvisioningCheck",1,1,1,,,,,,,,,,,,,,,, # set-moverequest,test4@kc2.extest.microsoft.com,,,,,,,,0,0,,,,,,,,,,,,,,, # resume-moverequest,test4@kc2.extest.microsoft.com,,,,,,,,,,,,,,,,,,,,,,,, # remove-moverequest,test4@kc2.extest.microsoft.com,,,,,,,,,0,,,,,,,,,,,,,,, # Sample2: # Operation,Identity,Confirm # remove-moverequest,test1@kc2.extest.microsoft.com,0 # remove-moverequest,test4@kc2.extest.microsoft.com,0 # # $recs = gc .\records.csv # # .\BulkMove-Mailbox.ps1 -Records $recs -tenantname 'kc2.extest.microsoft.com' -Test 'false' # # # Copyright (c) Microsoft Corporation. All rights reserved. # # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK # OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. [CmdletBinding()] param( [Parameter(Mandatory = $false)] [string]$BatchName, [Parameter(Mandatory = $false)] [string]$InputFile, [Parameter(Mandatory = $false)] [String]$LogFile = $null, [String]$IgnoreExcludedFromInitialProvisioning = "False", [String]$Test = "True", [Parameter(Mandatory=$false)] $Records = $null, [Parameter(Mandatory=$false)] [string] $TenantName = $null ) if ($(Get-PSSnapin | ?{$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } function GetObjSearcher { $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchScope = "SubTree" $objSearcher.PropertiesToLoad.Add("msExchOURoot") | out-null $objSearcher.PropertiesToLoad.Add("homeMDB") | out-null $objSearcher.PropertiesToLoad.Add("msExchArchiveDatabaseLink") | out-null $objSearcher.PropertiesToLoad.Add("objectguid") | out-null $objSearcher.PropertiesToLoad.Add("msexchmailboxguid") | out-null $objSearcher.PropertiesToLoad.Add("msexcharchiveguid") | out-null $objSearcher.PropertiesToLoad.Add("msExchOrganizationUpgradeRequest") | out-null $RootDN = $(Get-User -resultsize 1).distinguishedname $RootDN = $RootDN.substring($RootDN.IndexOf("DC=")) $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$RootDN") return $objSearcher } function CreateMoveRequest($ArchiveOnly, $entry, $objectguid, $batchName, $Priority, $CompletedRequestAgeLimit, $PreventCompletion, $PrimaryOnly, $Protect, $BlockFinalization) { $nmrParams = @{} $nmrParams.Add("Identity", $objectguid) $nmrParams.Add("BatchName", $batchName) $nmrParams.Add("Priority", $Priority) $nmrParams.Add("CompletedRequestAgeLimit", $CompletedRequestAgeLimit) $nmrParams.Add("AllowLargeItems", $true) $nmrParams.Add("ErrorAction", "silentlycontinue") if ($ArchiveOnly) { $nmrParams.Add("ArchiveOnly", $true) if ($entry.TargetDatabase -ne $null -and $entry.TargetDatabase -ne "") { $nmrParams.Add("ArchiveTargetDatabase", $entry.TargetDatabase) } } else { if ($PrimaryOnly) { $nmrParams.Add("PrimaryOnly", $true) } if ($entry.TargetDatabase -ne $null -and $entry.TargetDatabase -ne "") { $nmrParams.Add("TargetDatabase", $entry.TargetDatabase) } } if($BlockFinalization) { $nmrParams.Add("SkipMoving", "BlockFinalization") } if($PreventCompletion) { $nmrParams.Add("PreventCompletion", $true) } if($Protect) { $nmrParams.Add("Protect", $true) } New-MoveRequest @nmrParams | out-null } function GetTargetDBVersion($dbName, $versionMap) { if($dbName -eq $null -or $dbName -eq "") { $dbName = "Empty" if($versionMap[$dbName] -eq $null) { if(test-path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup") { $setupKey = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup" } elseif(test-path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup") { $setupKey = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup" } else { return $null } $dbversion = "{0}.{1}" -f $($setupKey.MsiProductMajor), $($setupKey.MsiProductMinor) $versionMap[$dbName] = $dbversion } return $versionMap[$dbName] } else { $dagName = $($dbName.split("-"))[0] if($versionMap[$dagName] -eq $null) { $dag = Get-DatabaseAvailabilityGroup $dagName $server = Get-ExchangeServer $dag.Servers[0].ToString() $serverversion = $($server.AdminDisplayVersion.tostring().split(" "))[1] $versionMap[$dagName] = $serverversion } return $versionMap[$dagName] } } function GetOrgInfo($entry) { $orgName = $entry.orgName if($orgName -eq $null -or $orgName -eq "") { return $null } if($script:TenantVersion[$orgName] -eq $null) { if($orgname -eq "FirstOrg") { $script:TenantVersion[$orgName] = "IgNore" } else { $org = get-organization $orgName if($org -eq $null) { $script:TenantVersion[$orgName] = "None" $Failure = "Tenant_NotFound" $failedcount++ "$(Get-Date),$failedcount,`"$($entry.Guid)`",$objectGuid,`"Failed when checiking prevent completion`", $Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$($entry.ArchiveOnly),$($entry.Overwrite),$($entry.PreventCompletion),$($entry.BlockFinalization)" | Out-file $failureLog -append return $null } else { $versiondetails = $($org.AdminDisplayVersion.tostring().split("("))[1].split(".") $orgversion = "{0}.{1}" -f $versiondetails[0], $versiondetails[1] $script:TenantVersion[$orgName] = $orgversion if($org.IsUpgradingOrganization) { $script:TenantUpgrade[$orgName] = "Upgrade" } elseif($org.IsPilotingOrganization -and $org.ServicePlan.tostring() -match "E15.*Pilot") { $script:TenantUpgrade[$orgName] = "Pilot" } else { $script:TenantUpgrade[$orgName] = "None" } return $orgversion } } } return $script:TenantVersion[$orgName] } function NeedPreventCompletion($entry) { if($entry.orgName -eq $null -or $entry.orgName -eq "") { return $true } if($script:TenantVersion[$entry.orgName] -eq $null) { if($(GetOrgInfo $entry) -eq $null) { return $true } } if($script:TenantVersion[$entry.orgName] -eq "IgNore") { return $false } $targetDbVersion = GetTargetDBVersion $entry.targetdatabase $script:TargetDBs $orgVersion = $script:TenantVersion[$entry.orgName] $orgUpgrade = $script:TenantUpgrade[$entry.orgName] #Use Failure column to log the result for version query $Failure = "Targetdb version = {0} org version = {1} " -f $targetDbVersion, $orgVersion "$(Get-Date),$injected,$count,$($UserList.count),$($entry.Guid),$objectGuid,$Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$ArchiveOnly,$Priority,$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $LogFile -append if($targetDbVersion -eq $orgVersion) { return $false } elseif($entry.UpgradeRequest -eq "4" -and $orgUpgrade -eq "Pilot") { return $false } else { return $true } } function AllowOverwriteAll($entry) { if($entry.orgName -eq $null -or $entry.orgName -eq "") { return $false } $orgUpgrade = $script:TenantUpgrade[$entry.orgName] if($script:TenantVersion[$entry.orgName] -eq "None") { return $false } elseif($(NeedPreventCompletion $entry) -eq $false -and ($orgUpgrade -eq "Upgrade" -or $entry.orgName -eq "FirstOrg")) { return $true } else { return $false } } function RemoveMove($objectguid) { $request = get-moverequest $objectguid -ErrorAction SilentlyContinue if($request.requeststyle -eq "IntraOrg") { Remove-MoveRequest $objectguid -Confirm:$false -ErrorAction SilentlyContinue | out-null } } function AddStringParam($params, $name, $value) { if($value) { $params[$name] = $value } } function AddBoolParam($params, $name, $value) { if($value) { if($value -eq '1') { $params[$name] = $true } elseif($value -eq '0') { $params[$name] = $false } } } function IsTenantReadyForCutover($tenantName) { $val = (Get-ExchangeSettings XFR -ConfigName CutOverReadyTenantIds -Force).EffectiveSetting.Value if($val -eq $null) { return $false } else { $orgId = (get-organization $tenantName).ExternalDirectoryOrganizationId if($val.Contains($orgId )) { return $true } else { return $false } } } function CheckTenantGLSOverride($tenantName) { LogInfo "Checking the GLSOVerride for the tenant: $($TenantName)" $machineName = $env:COMPUTERNAME $server = get-ExchangeServer $machineName if(!$server -or ($server.serverrole -notmatch 'mailbox')) # if running on a non-mbx machine { $machineName = (get-exchangeserver | ? {$_.serverrole -match 'mailbox' -and $_.admindisplayversion -match '15.0'})[0].Name } $val = (Get-ExchangeSettings AdDriver -ConfigName GlsTenantOverrides -Server $machineName -Force).EffectiveSetting.Value if($val -eq $null) { LogError "Failed to find the AdDriver.GlsTenantOverrides value scoped to this machine: $machineName" exit } if($val.Contains(":$($TenantName):")) { LogInfo "Found the tenant in GlsTenantOverrides list of the machine: $machineName" } else { LogError "Failed to find the tenant in GlsTenantOverrides list" exit } } function LogInfo($str) { write-host $str $str = "$(get-date -Format 'HH:mm:ss, dd/MM/yyyy') - $($str)" $str | Out-file $LogFile -append -force } function LogError($str) { $str = "[Error] " + $str LogInfo $str $str = "$(get-date -Format 'HH:mm:ss, dd/MM/yyyy') - $($str)" $str | Out-file $failureLog -append -force } function GetParametersString($params) { $paramString = ""; foreach($key in $params.Keys) { $paramString += " -" + $key + ":" + $params[$key] } return $paramString } function ContructParams($record) { $params = @{} AddStringParam $params 'Identity' $record.Identity AddStringParam $params 'RemoteHostName' $record.RemoteHostName AddStringParam $params 'RemoteOrganizationName' $record.RemoteOrganizationName AddStringParam $params 'TargetDeliveryDomain' $record.TargetDeliveryDomain AddStringParam $params 'BadItemLimit' $record.BadItemLimit AddStringParam $params 'TargetDatabase' $record.TargetDatabase AddStringParam $params 'ArchiveTargetDatabase' $record.ArchiveTargetDatabase AddStringParam $params 'BatchName' $record.BatchName AddStringParam $params 'LargeItemLimit' $record.LargeItemLimit AddStringParam $params 'Priority' $record.Priority AddStringParam $params 'StartAfter' $record.StartAfter AddStringParam $params 'CompleteAfter' $record.CompleteAfter AddStringParam $params 'IncrementalSyncInterval' $record.IncrementalSyncInterval AddStringParam $params 'CompletedRequestAgeLimit' $record.CompletedRequestAgeLimit AddBoolParam $params 'Protect' $record.Protect AddBoolParam $params 'Remote' $record.Remote AddBoolParam $params 'PreventCompletion' $record.PreventCompletion AddBoolParam $params 'SuspendWhenReadyToComplete' $record.SuspendWhenReadyToComplete AddBoolParam $params 'Confirm' $record.Confirm AddBoolParam $params 'CheckInitialProvisioningSetting' $record.CheckInitialProvisioningSetting AddBoolParam $params 'AllowLargeItems' $record.AllowLargeItems AddBoolParam $params 'IgnoreRuleLimitErrors' $record.IgnoreRuleLimitErrors AddBoolParam $params 'DoNotPreserveMailboxSignature' $record.DoNotPreserveMailboxSignature AddBoolParam $params 'AcceptLargeDataLoss' $record.AcceptLargeDataLoss AddBoolParam $params 'ForceOffline' $record.ForceOffline if($record.SkipMoving) { $params['SkipMoving'] = $record.SkipMoving.split(',') } if($record.InternalFlags) { $params['InternalFlags'] = $record.InternalFlags.split(',') } return $params } function InitializeDirectory() { param([string] $path) if(-not(Test-Path -Path $path -PathType Container)) { [Void](New-Item -Path $path -ItemType Container) } $path } function GetLogFileName { if (Test-Path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup") { $version = "V14" } elseif (Test-Path "HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup") { $version = "V15" } else { throw "Can't find version regkey " } $exchangeInstallPath = (get-item HKLM:\SOFTWARE\Microsoft\ExchangeServer\$version\Setup).GetValue("MsiInstallPath") $LogDirectory = InitializeDirectory $(Join-Path $exchangeInstallPath "Logging\XFR") $now = [DateTime]::UtcNow.ToString("yyyyMMdd_HHmmss") $logFileName = "$LogDirectory\XFR$($now).$([guid]::NewGuid().ToString()).log" return $logFileName } ###############################################################Script Body####################################################################################################################### if($LogFile -eq $null -or $LogFile -eq '') { $LogFile = GetLogFileName } $failureLog = $LogFile + ".failure" write-Host "Log file: $($LogFile) Failure log file: $($failureLog)" if($TenantName) # if $TenantName is specified, cross forest move code path gets executed { CheckTenantGLSOverride $tenantName $isTenantReadyForCutOver = IsTenantReadyForCutover($TenantName) LogInfo "IsTenantReadyForCutOver: $isTenantReadyForCutOver" if($Records -eq $null) { LogError "Null 'Records' argument" exit } else { $Records = ConvertFrom-Csv $Records if($Records -eq $null -or $Records[0].Operation -eq $null) { LogError "Invalid 'Records' argument" exit } LogInfo "Processing $($Records.Count) records" foreach($record in $Records) { $params = ContructParams $record $cmdString = "$($record.Operation) $(GetParametersString($params))" if($record.SkipRecord -eq '1') { LogInfo "Skipping: '$($cmdString)'" } else { LogInfo "Executing: '$($cmdString)'" $operation = $record.Operation.ToLower(); if($record.CompleteAfter -ne $null -and ($isTenantReadyForCutOver -eq $false)) { $completeAfter = Get-Date $record.CompleteAfter if($completeAfter -lt (Get-Date).AddYears(1)) { LogError "Tenant is not ready for CutOver. New-MoveRequest should be called with CompleteAfter value greater than $((Get-Date).AddYears(1)). Command: '$($cmdString)'" continue; } } if(($operation -eq 'new-moverequest') -and ($isTenantReadyForCutOver -eq $false) -and ($record.PreventCompletion -ne '1') -and ($record.SkipMoving -NotMatch 'BlockFinalization')) { LogError "Tenant is not ready for CutOver. New-MoveRequest should be called with PreventCompletion:true or SkipMoving:BlockFinalization. Command: '$($cmdString)'" continue } if(($operation -eq 'set-moverequest') -and ($record.PreventCompletion -eq '0') -and ($isTenantReadyForCutOver -eq $false)) { LogError "Set-MoveRequest should not be called with PreventCompletion:false if the tenant is not ready for CutOver. Command: '$($cmdString)'" continue } if($Test -ne "True") { $error.clear() switch ($operation) { 'new-moverequest' { New-MoveRequest @params } 'set-moverequest' { Set-MoveRequest @params } 'remove-moverequest' {Remove-MoveRequest @params} 'resume-moverequest' {Resume-MoveRequest @params} default {'Invalid Operation. Name: $($record.Operation)'} } if ($error.count -gt 0) { LogError $Error[0] } } } } } LogInfo "Execution completed" } else # old BulkMove-Mailbox code is executed { $excludedMDB = @{} Get-MailboxDatabase | %{ if ($_.IsExcludedFromProvisioning -or ($_.IsExcludedFromInitialProvisioning -and $IgnoreExcludedFromInitialProvisioning -eq "False")) { $excludedMDB.add($_.Name, 1) }} $domain = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName $ForestMonitor = $domain.split(".")[0] + ".onmicrosoft.com" $objSearcher = GetObjSearcher $failedcount = 0 $injected = 0 $count = 0 $UserList = @(import-csv $InputFile) "Time,Injected,count,Totalcount,InputGuid,Guid,Failure,batchName,SourceDatabase,TargetDatabase,ArchiveOnly,Priority,Overwrite,PreventCompletion,BlockFinalization" | out-file $LogFile "Time, TotalFailurecount,MBXGuid,ObjectGuid, Failure, Failuredetail,batchName,SourceDatabase,TargetDatabase,ArchiveOnly,Overwrite,PreventCompletion,BlockFinalization" | out-file $failureLog $script:TargetDBs = @{} $script:TenantVersion = @{} $script:TenantUpgrade = @{} foreach ($entry in $UserList) { $count++ $Failure = "" $objectGuid = $entry.Guid $ArchiveOnly = $false if ($entry.ArchiveOnly -eq "TRUE") { $ArchiveOnly = $true } $PrimaryOnly = $false if ($entry.ArchiveOnly -eq "Primary") { $PrimaryOnly = $true } $priority = $entry.priority if ($priority -eq $null -or $priority -eq "") { $priority = "Normal" } $CompletedRequestAgeLimit = $entry.CompletedRequestAgeLimit if($CompletedRequestAgeLimit -eq $null -or $CompletedRequestAgeLimit -eq "") { $CompletedRequestAgeLimit = 0 } if ($entry.TargetDatabase -ne $null -AND $excludedMDB.contains($entry.TargetDatabase)) { $Failure = "$($entry.TargetDatabase) cannot be targeted of MBX move" } else { $GuidSearch="" ([guid]$objectGuid).tobytearray() | %{ ` $temp = [Convert]::ToString($_, 16); ` if ($temp.length -eq 1) {$temp = "0" + $temp} ` $GuidSearch += "\" + $temp; ` } $objSearcher.Filter = "(|(objectguid=$GuidSearch)(msExchMailboxGuid=$GuidSearch)(msExchArchiveGUID=$GuidSearch))" $colResult = $objSearcher.FindOne() if ($colResult -ne $null) { $objItem = $colResult.GetDirectoryEntry() $objDN = New-Object System.String(@($objItem.distinguishedname)) if($objItem.msExchOURoot -eq $null -or $objItem.msExchOURoot.tostring() -eq "") { if($($objDN.split(","))[1] -eq "CN=Users") { $entry | add-member -type NoteProperty -Name orgName -Value "FirstOrg" } } else { $entry | add-member -type NoteProperty -Name orgName -Value $($objItem.msExchOURoot.ToString().split(","))[0].substring("OU=".length) } $objectGuid = $(New-Object System.Guid(@($objItem.objectguid))).guid $MBXGuid = New-Object System.Guid(@($objItem.msexchmailboxguid)) $ArchiveGuid = New-Object System.Guid(@($objItem.msexcharchiveguid)) $entry | add-member -type NoteProperty -Name UpgradeRequest -Value $objItem.msExchOrganizationUpgradeRequest if ($entry.Guid -eq $MBXGuid.guid) { $ArchiveOnly = $false } elseif ($entry.Guid -eq $ArchiveGuid.guid) { $ArchiveOnly = $true } # don't load balance monitoring tenants if ($objDN -match "exchangemon.net,OU=Microsoft Exchange Hosted Organizations,DC=" -or $objDN -match $ForestMonitor) { $Failure = "Exclude_ExchangeMon" } elseif ($entry.SourceDatabase -ne $null -and $entry.SourceDatabase -ne "") { if("$($objItem.homemdb)" -notmatch $entry.SourceDatabase -and "$($objItem.msexcharchivedatabaselink)" -notmatch $entry.SourceDatabase) { $Failure = "SourceDatabase_Mismatch" } } } else { $Failure = "User_NotFound" } } if ($Failure -ne "") { $failedcount++ "$(Get-Date),$failedcount,`"$($entry.Guid)`",$objectGuid,`"Failed when checiking database matching`", $Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$($entry.ArchiveOnly),$($entry.Overwrite),$($entry.PreventCompletion),$($entry.BlockFinalization)" | Out-file $failureLog -append } elseif ($Test -eq "True") { sleep -Milliseconds 100 } else { $RemoveMR = $false $PreventCompletion = $false $Protect = $false $BlockFinalization = $false if ($entry.PreventCompletion -eq "True") { $PreventCompletion = $true } if ($entry.Delete -eq "True") { $RemoveMR = $true } if ($entry.Protect -eq "True") { $Protect = $true } if ($entry.BlockFinalization -eq "True") { $BlockFinalization = $true } if (!$PreventCompletion -and !$BlockFinalization) { $PreventCompletion = NeedPreventCompletion $entry if($PreventCompletion) { $failedcount++ $Failure = "org version doesn't match target version and not pilot mode" "$(Get-Date),$failedcount,`"$($entry.Guid)`",$objectGuid,`"PreventCompletion or BlockFinalizaiton should be true`", $Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$($entry.ArchiveOnly),$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $failureLog -append "$(Get-Date),$injected,$count,$($UserList.count),$($entry.Guid),$objectGuid,$Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$ArchiveOnly,$Priority,$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $LogFile -append continue } } $error.clear() if ($RemoveMR) { RemoveMove $objectguid } else { CreateMoveRequest $ArchiveOnly $entry $objectguid $batchName $Priority $CompletedRequestAgeLimit $PreventCompletion $PrimaryOnly $Protect $BlockFinalization } if ($error.count -gt 0) { $Failure = $Error[0].Categoryinfo.Reason if ($Failure -eq "ManagementObjectAlreadyExistsException") { $remove = $false $request = get-moverequest $objectguid -ErrorAction SilentlyContinue switch ($entry.Overwrite) { "all" { if(AllowOverwriteAll $entry) { $remove = $true } } "allIntra" { if($request.requeststyle -eq "IntraOrg" -and $(AllowOverwriteAll $entry)) { $remove = $true } } "completedIntra" { if($request.status -eq "completed" -and $request.requeststyle -eq "IntraOrg") { $remove = $true } } } if($remove) { Remove-MoveRequest $objectguid -Confirm:$false -ErrorAction SilentlyContinue | out-null } } "$(Get-Date),$injected,$count,$($UserList.count),$($entry.Guid),$objectGuid,$Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$ArchiveOnly,$Priority,$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $LogFile -append # repeat the inject 1 more time regardless whether the error has been resolved $error.clear() if ($RemoveMR) { RemoveMove $objectguid } else { CreateMoveRequest $ArchiveOnly $entry $objectguid $batchName $Priority $CompletedRequestAgeLimit $PreventCompletion $PrimaryOnly $Protect $BlockFinalization } if ($error.count -gt 0) { $Failure = $Error[0].Categoryinfo.Reason $failedcount++ "$(Get-Date),$failedcount,`"$($entry.Guid)`",$objectGuid,`"retry still failed`", $Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$($entry.ArchiveOnly),$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $failureLog -append $error.clear() } else { $Failure = "" } } } if ($Failure -eq "") { $injected++ $Failure = "Success" } "$(Get-Date),$injected,$count,$($UserList.count),$($entry.Guid),$objectGuid,$Failure,$batchName,$($entry.SourceDatabase),$($entry.TargetDatabase),$ArchiveOnly,$Priority,$($entry.Overwrite),$PreventCompletion,$BlockFinalization" | Out-file $LogFile -append } } # SIG # Begin signature block # MIIauQYJKoZIhvcNAQcCoIIaqjCCGqYCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUKQ+q/XKxaMQgC5k8dJuiI+xR # ZOOgghV6MIIEuzCCA6OgAwIBAgITMwAAAFnWc81RjvAixQAAAAAAWTANBgkqhkiG # 9w0BAQUFADB3MQswCQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4G # A1UEBxMHUmVkbW9uZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMSEw # HwYDVQQDExhNaWNyb3NvZnQgVGltZS1TdGFtcCBQQ0EwHhcNMTQwNTIzMTcxMzE1 # WhcNMTUwODIzMTcxMzE1WjCBqzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAw # DgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24x # DTALBgNVBAsTBE1PUFIxJzAlBgNVBAsTHm5DaXBoZXIgRFNFIEVTTjpGNTI4LTM3 # NzctOEE3NjElMCMGA1UEAxMcTWljcm9zb2Z0IFRpbWUtU3RhbXAgU2VydmljZTCC # ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMZsTs9oU/3vgN7oi8Sx8H4H # zh487AyMNYdM6VE6vLawlndC+v88z+Ha4on6bkIAmVsW3QlkOOJS+9+O+pOjPbuH # j264h8nQYE/PnIKRbZEbchCz2EN8WUpgXcawVdAn2/L2vfIgxiIsnmuLLWzqeATJ # S8FwCee2Ha+ajAY/eHD6du7SJBR2sq4gKIMcqfBIkj+ihfeDysVR0JUgA3nSV7wT # tU64tGxWH1MeFbvPMD/9OwHNX3Jo98rzmWYzqF0ijx1uytpl0iscJKyffKkQioXi # bS5cSv1JuXtAs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