PoshCode Logo PowerShell Code Repository

Invoke-ADMTUserMigration by Jan Egil Ring 6 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2046"></script>download | new post

This is an example on how to script the Active Directory Migration Tool (ADMT) using PowerShell.

  1. ###########################################################################"
  2. #
  3. # NAME: Invoke-ADMTUserMigration.ps1
  4. #
  5. # AUTHOR: Jan Egil Ring
  6. # EMAIL: jan.egil.ring@powershell.no
  7. #
  8. # COMMENT: This is an example on how to script the Active Directory Migration Tool (ADMT) using PowerShell.
  9. #          It`s based on the sample templatescript.vbs which resides in the ADMT installation-directory.
  10. #          NOTE: Since ADMT is a 32-bit application, this script must be run from Windows PowerShell (x86).
  11. #          It also requires elevated privileges.
  12. #
  13. #          For more details, see the following blog-post:
  14. #          http://blog.powershell.no/2010/08/04/automate-active-directory-migration-tool-using-windows-powershell
  15. #
  16. # You have a royalty-free right to use, modify, reproduce, and
  17. # distribute this script file in any way you find useful, provided that
  18. # you agree that the creator, owner above has no warranty, obligations,
  19. # or liability for such use.
  20. #
  21. # VERSION HISTORY:
  22. # 1.0 04.08.2010 - Initial release
  23. #
  24. ###########################################################################"
  25.  
  26. ### BEGIN ADMT Scripting Constants ###
  27.  
  28. # PasswordOption constants
  29.  
  30. $admtComplexPassword                   = "&H0001"
  31. $admtCopyPassword                      = "&H0002"
  32. $admtDoNotUpdatePasswordsForExisting   = "&H0010"
  33.  
  34. # ConflictOptions constants
  35.  
  36. $admtIgnoreConflicting           = "&H0000"
  37. $admtMergeConflicting            = "&H0001"
  38. $admtRemoveExistingUserRights    = "&H0010"
  39. $admtRemoveExistingMembers       = "&H0020"
  40. $admtMoveMergedAccounts          = "&H0040"
  41.  
  42. # DisableOption constants
  43.  
  44. $admtLeaveSource        = "&H0000"
  45. $admtDisableSource      = "&H0001"
  46. $admtTargetSameAsSource = "&H0000"
  47. $admtDisableTarget      = "&H0010"
  48. $admtEnableTarget       = "&H0020"
  49.  
  50. # SourceExpiration constant
  51.  
  52. $admtNoExpiration = "-1"
  53.  
  54. # Translation Option
  55.  
  56. $admtTranslateReplace = "0"
  57. $admtTranslateAdd     = "1"
  58. $admtTranslateRemove  = "2"
  59.  
  60. # Report Type
  61.  
  62. $admtReportMigratedAccounts  = "0"
  63. $admtReportMigratedComputers = "1"
  64. $admtReportExpiredComputers  = "2"
  65. $admtReportAccountReferences = "3"
  66. $admtReportNameConflicts     = "4"
  67.  
  68. # Option constants
  69.  
  70. $admtNone     = "0"
  71. $admtData     = "1"
  72. $admtFile     = "2"
  73. $admtDomain   = "3"
  74. $admtRecurse           = "&H0100"
  75. $admtFlattenHierarchy  = "&H0000"
  76. $admtMaintainHierarchy = "&H0200"
  77.  
  78. # Event related constants
  79.  
  80. # Progress type
  81. $admtProgressObjectMigration   = "0"
  82. $admtProgressAgentDispatch     = "1"
  83. $admtProgressAgentOperation    = "2"
  84. $admtProgressMailboxMigration  = "3"
  85.  
  86. # Event type
  87. $admtEventNone                         = "0"
  88. $admtEventObjectInputPreprocessed      = "1"
  89. $admtEventTaskStart                    = "2"
  90. $admtEventTaskFinish                   = "3"
  91. $admtEventObjectProcessed              = "4"
  92. $admtEventGroupMembershipProcessed     = "5"
  93. $admtEventAgentStatusUpdate          ="6"
  94. $admtEventAgentNotStarted = "7"
  95. $admtEventAgentFailedToStart = "8"
  96. $admtEventAgentWaitingForReboot = "9"
  97. $admtEventAgentRunning = "10"
  98. $admtEventAgentCancelled = "11"
  99. $admtEventAgentPassed = "12"
  100. $admtEventAgentFailed = "13"
  101. $admtEventAgentWaitingForRetry = "14"
  102. $admtEventAgentSuccessful = "15"
  103. $admtEventAgentCompletedWithWarnings = "16"
  104. $admtEventAgentCompletedWithErrors = "17"
  105. $admtEventTaskLogSaved = "18"
  106.  
  107. $admtAgentPreCheckPhase = "&H100"
  108. $admtAgentAgentOperationPhase = "&H200"
  109. $admtAgentPostCheckPhase = "&H300"
  110.  
  111. $admtAgentStatusMask = "&HFF"
  112. $admtAgentPhaseMask = "&H300"
  113.  
  114. # Status type
  115. $admtStatusSuccess   = "0"
  116. $admtStatusWarnings  = "1"
  117. $admtStatusErrors    = "2"
  118.  
  119. ### END ADMT Scripting Constants ###
  120.  
  121. #Creates an instance of an ADMT migration object using the COM-object provided with ADMT
  122. $Migration = New-Object -ComObject "ADMT.Migration"
  123. $Migration.IntraForest = $false
  124. $Migration.SourceDomain = "contoso-old.local"
  125. $Migration.SourceDomainController = "dc01.contoso-old.local"
  126. $Migration.SourceOU = "Europe/Norway/Oslo"
  127. $Migration.TargetDomain = "contoso-new.local"
  128. $Migration.TargetDomainController = "dc02.contoso-new.local"
  129. $Migration.TargetOU = "Europe/Norway/Oslo"
  130. $Migration.PasswordOption = $admtComplexPassword
  131. $Migration.PasswordServer = "dc01.contoso-old.local"
  132. $Migration.PasswordFile = "C:\WINDOWS\ADMT\Logs\Passwords.txt"
  133. $Migration.ConflictOptions = $admtIgnoreConflicting
  134. $Migration.UserPropertiesToExclude = ""
  135. $Migration.InetOrgPersonPropertiesToExclude = ""
  136. $Migration.GroupPropertiesToExclude = ""
  137. $Migration.ComputerPropertiesToExclude = ""
  138. $Migration.SystemPropertiesToExclude = ""
  139. $Migration.PerformPreCheckOnly = $false
  140. $Migration.AdmtEventLevel = $admtStatusWarnings
  141. $Migration.CommandLine = $false
  142.  
  143. #Creates an user migration object
  144. $UserMigration = $Migration.CreateUserMigration()
  145. $UserMigration.DisableOption = $admtTargetSameAsSource
  146. $UserMigration.SourceExpiration = $admtNoExpiration
  147. $UserMigration.MigrateSIDs = $true
  148. $UserMigration.TranslateRoamingProfile = $false
  149. $UserMigration.UpdateUserRights = $false
  150. $UserMigration.MigrateGroups = $false
  151. $UserMigration.UpdatePreviouslyMigratedObjects = $false
  152. $UserMigration.FixGroupMembership = $true
  153. $UserMigration.MigrateServiceAccounts = $false
  154.  
  155. #Initiates user migration. Logs are written to C:\Windows\ADMT\Logs by default.
  156. $UserMigration.Migrate($admtDomain,$null,$null)
  157.  
  158. #Creates a password migration object
  159. $PasswordMigration = $Migration.CreatePasswordMigration()
  160.  
  161. #Initiates password migration. Logs are written to C:\Windows\ADMT\Logs by default.
  162. $PasswordMigration.Migrate($admtDomain,$null,$null)

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