Hi @Smruti Ranjan Nayak ,
Welcome to Q&A Forum!
Please follow the steps:
1.Prepare a CSV file and fill in the following relevant information. The CSV file just maps the old SAMAccountName with the new one.
For example:
$OldID="i:0#.w|DomainA\userA"
$NewID="i:0#.w|DomainB\userA"
#OR
$OldID="DomainA\userB"
$NewID="DomainB\userB"
Here is my CSV file structure:
2.PowerShell script to Migrate Users from one domain to another:
Add-PSSnapin Microsoft.SharePoint.PowerShell
#Import data from CSV file
$UserData = Import-CSV -path "C:\temp\Accounts.csv"
#Iterate through each Row in the CSV
foreach ($Row in $UserData)
{
write-host "Processing user:" $row.Email
#Site collection URL
$siteURL ="http://sp19"
$site = Get-SPSite $siteURL
foreach($web in $site.AllWebs)
{
#Get All Users
$UserColl = Get-SPUser -web $web.Url
foreach ($User in $UserColl)
{
#Get values from CSV File
$OldUserID= $Row.OldUserID.Trim()
$NewUserID =$Row.NewUserID.Trim()
$Email = $Row.Email.Trim()
#Search for Old User Accounts
if($User.UserLogin.Contains($OldUserID))
{
#Update the User E-mail
Set-SPUser -Identity $User.UserLogin -Email $Email -Web $web.URL
$NewUser = $User.UserLogin.replace($OldUserID, $NewUserID)
#Migrate user from Old account to new account - migrate users to new domain
Move-SPUser -Identity $User -NewAlias $NewUser -IgnoreSID -confirm:$false
write-host "User Migrated: $($User.userlogin) at site $($web.Url)"
}
}
}
}
3.Migrate AD Groups in SharePoint from Old Domain to New Domain:
Use this PowerShell script to migrate active directory security groups from one domain to another domain.
#Old and New Groups
$OldLogin="OldDomain\Group"
$NewLogin="NewDomain\Group"
#Migrate AD Group
$Farm = Get-SPFarm
$Farm.MigrateGroup($OldLogin, $NewLogin)
Reference:
Thanks,
Echo Du
=====================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.