Migrate Users / Groups Between different domain

1.Farm Level.

  a.Powershell Script

    SPFarm.MigrateUserAccount

Add-PSSnapin Microsoft.SharePoint.PowerShell
function MigrateUserOrGroups($migrationType, $csvFile)
{
   #Getting the SPFarm object
   $farm = Get-SPFarm
   Write-Host $migrationType
   #Checking whether the user input the type of Migration as Group
   if($migrationType -eq "Group"){
   Import-Csv $csvFile | ForEach-Object{
      Write-Host "Migrating Group" $_.oldlogin "to" $_.newlogin -ForegroundColor Green
      $farm.MigrateGroup($_.oldlogin, $_.newlogin)
       }
      }
    #Checking whether the user input the type of Migration as User
    if($migrationType -eq "User")
      {
        Import-Csv $csvFile | ForEach-Object{
        Write-Host "Migrating User" $_.oldlogin "to" $_.newlogin -ForegroundColor Green
        $farm.MigrateUserAccount( $_.oldlogin, $_.newlogin, $false )
        }      
      }
   Write-Host "Migration Completed" -ForegroundColor Cyan
   # $farm.Name
}

2.Site Collection Level.

  a.PowerShell Script

    Move-SPuser

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 can use Move-SPUser cmdlet in situations like:
  1. User Account deleted and Recreated in AD (with new Sid)
  2. User Account changed from One Domain to another domain
  3. User Account's Login ID is changed (such as due to last name change).

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. 
1
2
3
4
5
6
7
#Old and New Groups
$OldLogin="OldDomain\Group"
$NewLogin="NewDomain\Group"
 
#Migrate AD Group
$Farm = Get-SPFarm
$Farm.MigrateGroup($OldLogin, $NewLogin)

Ok. Now, How to get all unique users and AD Groups to CSV file at site collection-web application or Farm level ? Well, use these PowerShell scripts:

Read more: http://www.sharepointdiary.com/2014/12/migrate-sharepoint-users-from-one-domain-to-another.html#ixzz4olbVL8pq
 
 

Now with SharePoint 2013, Its replaced with the PowerShell cmdlet: Move-SPUser.

1
2
3
4
5
6
7
8
$Web = Get-SPWeb $WebURL
 
$OldID="i:0#.w|Crescent\Opera1"
$NewID="i:0#.w|Crescent\Opera2"
 
$OldUser = $Web.EnsureUser($OldID)
Move-SPUser –Identity $OldUser -NewAlias $NewID -ignoresid -Confirm:$false

Read more: http://www.sharepointdiary.com/2014/12/migrate-sharepoint-users-from-one-domain-to-another.html#ixzz4oldlUyVK
 
posted @ 2017-08-04 15:00  【上海】Peter  阅读(654)  评论(0)    收藏  举报