PowerShell script to Migrate Active Directory From 2012 to Server 2016

PowerShell script to Migrate Active Directory

# Import the Active Directory module
Import-Module ActiveDirectory

# Install the Active Directory Domain Services (AD DS) role
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools

# Promote the server to a domain controller
Install-ADDSDomainController -DomainName “example.com” -InstallDns:$true -CreateDnsDelegation:$false

# Migrate the schema to the latest version
Update-ADSchema

# Migrate the global catalog to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 0,1,2,3,4 -PassThru

# Migrate the domain naming master to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 5 -PassThru

# Migrate the infrastructure master to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 6 -PassThru

# Migrate the PDC emulator to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 7 -PassThru

# Migrate the RID master to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 8 -PassThru

# Migrate the schema master to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 9 -PassThru

# Migrate the domain controller to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 10 -PassThru

# Migrate the time server to the new domain controller
Move-ADDirectoryServerOperationMasterRole -Identity “olddc.example.com” -OperationMasterRole 11 -PassThru

# Demote the old domain controller
Uninstall-ADDSDomainController -DemoteOperationMasterRole:$true

This script performs the following tasks:

  1. Imports the Active Directory module.
  2. Installs the AD DS role on the new server.
  3. Promotes the new server to a domain controller.
  4. Migrates the schema to the latest version.
  5. Migrates the global catalog, domain naming master, infrastructure master, PDC emulator, RID master, schema master, domain controller, and time server roles to the new domain controller.
  6. Demotes the old domain controller.

Note that this script assumes that the new domain controller is being installed in the same domain as the old domain controller, and that the old domain controller is still functioning properly. If these assumptions are not correct, you may need to modify the script or perform the migration using a different method.

Leave a Reply

Your email address will not be published. Required fields are marked *