PoshCode Logo PowerShell Code Repository

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

A function to migrate a single user in the Active Directory Migration Tool, based on the sample script Invoke-ADMTUserMigration.ps1: http://poshcode.org/2046
Added support for pipeline input (thanks to Shay Levy for the suggestion)

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

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