I want to migrate AD domain group "old\abc" to "new\abc"" domain in sharpeoint 2010 using powershell.

I am using powershell to run

stsadm -o migrategroup –oldlogin old\abc  –newlogin new\abc

but I want to know if there are any other better methods of doing it in sharpeoint 2010 as stsadm is used for 2007.

also please tell me how to run above command if AD group contains spaces between their names.

2 Answers 2


Ready PowerShell script for migrating both users and groups when you have CSV of old and new account names is here.

Save the following into Migrate.ps1 (or whatever).

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

MigrateUserOrGroups $args[0] $args[1]

CSV format


Call the .ps1 either .\Migrate1.ps1 "User" .\users.csv or .\Migrate.ps1 "Group" .\groups.csv

  • $farm.MigrateGroup($_.oldlogin, $_.newlogin) worked for me. Thanks Oct 18, 2014 at 6:09

You can do a migration like this using PowerShell using the MigrateUserAccount and MigrateGroup method. SPFarm.MigrateUserAccount can be used in the same was as stsadm -o migrateuser.

Full syntax, once you've grabbed the farm object with Get-SPFarm and assigned an object $farm is:

  • $farm.MigrateGroup($oldlogin, $newlogin)
  • $farm.MigrateUserAccount($oldlogin, $newlogin, $false)

The boolean value on the MigrateUserAccount specifies whether or not to query AD and check the SID history. If $true it will confirm that the SID is the same for both accounts.

Also to run the stsadm command with spaces in names, simply surround the values with "", e.g. "My Domain\Old Username".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.