Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Migrate SharePoint Users from One Domain To Another

$
0
0
Requirement:
During a acquisition, Our company decided to merge with an acquired company's AD by re-creating their user Ids in our AD. Also, the acquired company had a bunch SharePoint sites and we wanted to migrate them to our SharePoint environment.

That brought an another challenge of re-mapping user Ids with permission between domains. How do we migrate SharePoint users from one domain to another domain?

Solution: 
Well, In SharePoint 2007 days, I used STSADM to migrate users between domains:
Stsadm -o migrateuser -oldlogin domain\OldUserID -newlogin domain\NewUserID -ignoresidhistory 

Now with SharePoint 2013, Its replaced with the PowerShell cmdlet: Move-SPUser. So, rather moving users one by one, we prepared a CSV file, mapping users from one domain to new domain and used PowerShell script to migrate users in bulk.

Here is my CSV file structure:
sharepoint migrate users between domains

The csv file just maps old SAMAccountName with the new one.

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:\Accounts.csv"

#Iterate through each Row in the CSV
foreach ($Row in $UserData)
{
write-host "Processing user:" $row.Email

#Site collection URL
$siteURL ="https://intranet.crescent.com"
$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)"
}

}
}
}
This PowerShell script migrates users to new domain programmatically. You have to use the same method when users leaves the company and rejoin - if their AD accounts are deleted and re-created.

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>