Changing Domains and Sharepoint what to do to migrate users to the new domain name

Posted: Monday 5 December 2011 by Khalid Ameerodien in Labels:
1

I got this nifty little script at the last information worker session and found that it could be rather useful when migrating to a new domain.

//**************************BEGIN CODE*************************************
param([string]$url = (Read-Host "Enter the Url of the Web Application: "), `

[string]$oldprovider = `(Read-Host "Enter the Old Provider Name (Example -> Domain\ or MembershipProvider:) "), `
[string]$newprovider = `(Read-Host "Enter the New Provider Name (Example -> Domain\ or i:0#.f
MembershipProvider
) "))
add-pssnapin microsoft.sharepoint.powershell -EA 0
# Get all of the users in a site
$users = get-spuser -web $url
# Set a conversion flag which will later be used to verify if you want to continue processing
$convert = $false
# Loop through each of the users in the site
foreach($user in $users)
{
# Create an array that will be used to split the user name from the domain/membership provider
$a=@()
$displayname = $user.DisplayName
$userlogin = $user.UserLogin
# Separate the user name from the domain/membership provider
if($userlogin.Contains(':'))
{
$a = $userlogin.split(":")
$username = $a[1]
}
elseif($userlogin.Contains('\'))
{
$a = $userlogin.split("\")
$username = $a[1]
}
# Create the new username based on the given input
$newalias = $newprovider + $username
if (-not $convert)
{
$answer = Read-Host "Your first user will be changed from $userlogin to $newalias. Would you like to continue processing all users? [Y]es, [N]o"
switch ($answer)
{
"Y" {$convert = $true}
"y" {$convert = $true}
default {exit}
}
}
if(($userlogin -like "$oldprovider*") -and $convert)
{
move-spuser -identity $user -newalias "$newalias" -ignoresid -Confirm:$false
}
}
//**************************END CODE*************************************

 

Thanks to Bradley Chetty for the script it makes life alot easier. Visit his blog @ http://bradleychetty.blogspot.com/

 

1 comments:

  1. ErockP3 says:

    nice, can you fix the bug in the code that loses the \ in the target domain name?