How to Change the Domain of Multiple SharePoint Accounts

Very recently I had to change a bunch of accounts from one domain to another in SharePoint. Rather than doing this piecemeal for each individual account, I decided to write a simple script to do this for me. Since I couldn’t find this online, I figured I’d demonstrate how I did it.

 
 

Start by creating a 2 column Comma Separated Value (CSV) file. This is just a plain text file where the left side is the original domain of the user, and the right side is the *new* domain for that same user. In my case we were using SP2010 and moving the users from classic to claims, so I added a claims token in at the same time.

 
 

The CSV File

(Original domain user on left, updated domain user on right. I saved this file under c:\top\out.csv)

 
 

ABC-NA\enwqc,i:0#.w|COMPANY\enwqc

ABC-NA\eotib,i:0#.w|COMPANY\eotib

ABC-NA\ergyp,i:0#.w|COMPANY\ergyp

 
 

Next, I needed some PowerShell that would read the CSV file, and process each user (move them from the old domain to the new domain)

 
 

The PowerShell Code

(Note: You need to specify the SharePoint site (Web) that you want to apply this change to – yes, you have to do this site by site. Update the URL in the code below before proceeding)

 
 

$path = “c:\top\out.csv”

Import-Csv $path -Header Name,Value | Foreach-Object{

$old = $_.Name

$new = $_.Value

write-host “about to update user $old to $new.”

$user = get-SPUser -Identity “$old” -Web https://[DOMAIN]/sites/[SITE]

Move-SPUser -Identity $user -IgnoreSID -NewAlias “$new” -Confirm:$false

}

 
 

To run this script, simply copy the lines above and paste it into a SharePoint Administrator PowerShell. The output will look similar to what you see below.

 
 

The Script Running…

 
 

about to update user ABC-NA\ggdxb to i:0#.w|COMPANY\ggdxb.

about to update user ABC-NA\gcmuy to i:0#.w|COMPANY\gcmuy.

about to update user ABC-NA\evlgx to i:0#.w|COMPANY\evlgx.

 
 

There’s obviously an improvement that could be made to this script in that it could also be written to iterate over a collection of sites (webs), but I didn’t have a need to do that. To do this, you would simply wrap the code above in another foreach-object and provide a parameter for the “-Web” option.

 
 

Hopefully this helps someone else to save a bit of time in the future.