PoshCode Logo PowerShell Code Repository

Invoke-MoveRequest by Jan Egil Ring 6 years ago (modification of post by Jan Egil Ring view diff)
View followups from laurent pierre | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1838"></script>download | new post

Script to use when migrating mailboxes to Microsoft Exchange Server 2010 Cross-Forest. Prepares user objects already moved to the target forest using Active Directory Migration Tool or other tools, and then invokes the mailbox move request.
For more information, see the following blog-post: http://blog.powershell.no/2010/04/23/exchange-server-2010-cross-forest-migration
Update 13.05.2010: Fixed a couple of variable names that was wrong after “generalizing” the script

  1. ###########################################################################
  2. #
  3. # NAME: Invoke-MoveRequest.ps1
  4. #
  5. # AUTHOR: Jan Egil Ring
  6. # EMAIL: jer@powershell.no
  7. #
  8. # COMMENT: Script to use when migrating mailboxes to Microsoft Exchange Server 2010 Cross-Forest. Prepares user objects already
  9. #          moved to the target forest using Active Directory Migration Tool or other tools, and then invokes the mailbox move request.
  10. #          For more information, see the following blog-post: http://blog.powershell.no/2010/04/23/exchange-server-2010-cross-forest-migration
  11. #
  12. # You have a royalty-free right to use, modify, reproduce, and
  13. # distribute this script file in any way you find useful, provided that
  14. # you agree that the creator, owner above has no warranty, obligations,
  15. # or liability for such use.
  16. #
  17. # VERSION HISTORY:
  18. # 1.0 23.04.2010 - Initial release
  19. #
  20. ###########################################################################
  21.  
  22. #Adding Quest AD PowerShell Commands Snapin and Microsoft Exchange Server 2010 PowerShell Snapin
  23. Add-PSSnapin Quest.ActiveRoles.ADManagement
  24. Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
  25.  
  26. #Custom variables, edit this section
  27. $TargetDatabase = "Mailbox Database A"
  28. $TargetDeliveryDomain = "domain.com"
  29. $TargetForest="DomainA.local"
  30. $SourceForest="domainB.local"
  31. $SourceForestGlobalCatalog = "dc-01.domainB.local"
  32. $SourceForestCredential = Get-Credential -Credential "Domain\SourceForestAdministrator"
  33.  
  34. #Connect to source forest to collect users to migrate
  35. Connect-QADService -Service $SourceForest | Out-Null
  36. $SourceForestUsersToMigrate = Get-QADUser -SearchRoot "DomainA.local/Department A/Users"
  37.  
  38.  
  39. foreach ($user in $SourceForestUsersToMigrate) {
  40.  
  41. Write-Host "Processing user $user" -ForegroundColor Yellow
  42.  
  43. #Connect to source forest to collect source object attributes
  44. Connect-QADService -Service $SourceForest | Out-Null
  45. $TargetObject=$user.samaccountname
  46. $SourceObject=Get-QADUser $TargetObject -IncludeAllProperties
  47. $mail=$SourceObject.Mail
  48. $mailNickname=$SourceObject.mailNickname
  49. [byte[]]$msExchMailboxGUID=(Get-QADuser $SourceObject -IncludedProperties msExchMailboxGUID -DontConvertValuesToFriendlyRepresentation).msExchMailboxGUID
  50. $msExchRecipientDisplayType="-2147483642"
  51. $msExchRecipientTypeDetails="128"
  52. $msExchUserCulture=$SourceObject.msExchUserCulture
  53. $msExchVersion="44220983382016"
  54. $proxyAddresses=$SourceObject.proxyAddresses
  55. $targetAddress=$SourceObject.Mail
  56. $userAccountControl=514
  57.  
  58. #Connect to target forest to set target object attributes
  59. Connect-QADService -Service $TargetForest | Out-Null
  60. Set-QADUser -Identity $TargetObject -ObjectAttributes @{mail=$mail;mailNickname=$mailNickname;msExchMailboxGUID=$msExchMailboxGUID;msExchRecipientDisplayType=$msExchRecipientDisplayType;msExchRecipientTypeDetails=$msExchRecipientTypeDetails;msExchUserCulture=$msExchUserCulture;msExchVersion=$msExchVersion;proxyAddresses=$proxyAddresses;targetAddress=$targetAddress;userAccountControl=$userAccountControl} | Out-Null
  61.  
  62. #Update Exchange-attributes (LegacyExchangeDN etc.)
  63. Get-MailUser $TargetObject | Update-Recipient
  64.  
  65. #Invoking a new move-request
  66. New-MoveRequest -Identity $TargetObject -RemoteLegacy -TargetDatabase $TargetDatabase -RemoteGlobalCatalog $SourceForestGlobalCatalog -RemoteCredential $SourceForestCredential -TargetDeliveryDomain $TargetDeliveryDomain
  67.  
  68. #Enable target object and unset "User must change password at next logon"
  69. Enable-QADUser -Identity $TargetObject | Out-Null
  70. Set-QADUser -Identity $TargetObject -UserMustChangePassword $false | Out-Null
  71. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me