Migrate Groups from one domain to another domain

Posted: July 28, 2015 in Powershell, SharePoint 2010

There is a post that seems to be the authority on migrating groups between domains:

http://blogs.msdn.com/b/sowmyancs/archive/2012/01/07/migrate-users-groups-powershell-script.aspx

The problem with this script is that it only corrects the “Account” portion of the listing in the collections, it does not update the display name of the group.

So starting from the script in the above link – here it is with a couple tweaks in the group section.

# ======================================================================
# Microsoft PowerShell Script
#
# NAME:           Migrate_Groups.ps1
# AUTHOR:       Scott
# DATE:           6/9/2015
#
# DESCRIPTION:     Migrates groups from one domain to another
#
#                Needs to be appended with a .csv file that includes to columns oldlogin,newlogin.
#                Both columns needs to have the domain prepended to the group name.
#
# EXAMPLE:
#                .\Migrate_Groups.ps1 Group import.csv
#
#                Example CSV
#                    oldlogin,newlogin
#                    OLDDOMAIN\old group,NEWDOMAIN\new group
#
#
# RESOURCE:
#                  http://sharepoint.stackexchange.com/questions/118424/how-to-migrate-ad-domain-groups-in-sharepoint-2010
#
# ======================================================================

if ( (Get-PSSnapin -Name “Microsoft.SharePoint.Powershell” -ErrorAction SilentlyContinue) -eq $null )

{
Add-PsSnapin “Microsoft.SharePoint.Powershell”
}

$URL = Read-Host “Enter Web App URL”
$site = New-Object -TypeName Microsoft.SharePoint.SPSite -ArgumentList $URL

function MigrateUserOrGroups($migrationType, $csvFile)
{
#Getting the SPFarm object
$farm = Get-SPFarm

Write-Host Migration Type: $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)
$newlogin = $_.newlogin
$group = $site.RootWeb.SiteUsers[$newlogin]
Write-host Newlogin: $newlogin
$group.Name = $newlogin
$group.Update()
}
}

#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
}

MigrateUserOrGroups $args[0] $args[1]

 

Leave a comment