one of my customers did a domain renaming lately in his network. Unfortunately, he forgot to consider his SharePoint environment and was wondering why the bad SharePoint system is not working after this “small” environmental change. Unfortunately, he also forgot to mention this important structural change to me before
(but this is another story).
“The roof… the roof. The roof is on fire” is a part of a famous song of the band the Bloodhound Gang. This probably describes exactly how the whole situation was looking like.
Fortunately, it took me not all too much to make SharePoint running again. The first step was to update the SharePoint service accounts and to do a system reboot. After this, the central administration was working again. So far… so good.
Nevertheless, there was still an additional problem. I managed to access the central administration, however, the users did not manage to login into their TeamSites. After checking the TeamSite I discovered that the permission assignments of these users still showed the old account name references (with old domain). Therefore, it was necessary to update them to reference to the new domain. I found two solutions to do this:
Solution 1: Manual work
- Update the site collection admin in central administration for the site
- Login with this account on the TeamSite
- Assign again the permissions to each single user. This changes automatically the account references with the new domain name
Solution 2: Powershell
After the change of two users I was already worried about the time it might take to update all references. Therefore, I wrote a simple Powershell script that does the job for me. The idea is pretty simple. Let us use the “EnsureUser” method of the web (find here more info about this method) on each single user entry. This makes the same changes and updates the account references for us.
Please note that I executed this script only one one single site collection. You can change it to many site collections without any problems.
Add-PSSnapin Microsoft.SharePoint.Powershell
$rootWeb = Get-SPWeb "yoursite"
$oldDomain = "yourOldDomain"
$newDomain = "yourNewDomain"
#loop through all users in the $rootWeb, change the login name and execute the EnsureUser method
foreach ($user in $rootWeb.Users) {
$newLogin = $user.UserLogin -replace $oldDomain, $newDomain
$rootWeb.EnsureUser($newLogin)
}
As usual, before executing such scripts, ensure that you backed up your system before.
It could be that there is a more elegant solution out there that does this job faster, however, in this special case this was my rescue.
Hope this helps,
Patrick


Hi Patrick, Nice solution. Just wondering if there's a way to ensure that the old accounts are deleted.
Also, will all the users permissions and group memberships remain the same?
Thanks,
Joe
Hi Joe,
check out this solution provided by another colleague:
http://nikspatel.wordpress.com/2010/08/10/delete-orphaned-ad-users-from-the-site-collection/
br,
patrick