Is there any Powershell command to migrate all the 1000+ user accounts from old AD domain to new domain? If yes, what will be the possible powershell script?

Any sample Powershell script or reference needed?

  • How this relates to SharePoint? Nov 14, 2014 at 13:37
  • Because solution is based on SharePoint
    – SPBeginer
    Nov 14, 2014 at 14:13

1 Answer 1


If you have a newer SP version (2010 or 2013) you could automate the process via iterating through the SiteUsers collection and call the Move-SPUser PowerShell CmdLet on each of them, but in 2007 it is not available. So if your question relates to the same SharePoint 2007 as your former question, then the answer is no, you cannot use Move-SPUser unless you upgrade the system to at least SP 2010. If you restrict to PowerShell, you can call standard SharePoint API methods or write your own CmdLets to call that API methods directly.

FYI, stsadm -o migrateuser calls the public MigrateUserAccount method of the Microsoft.SharePoint.Administration.SPFarm class, so you should call SPFarm.Local.MigrateUserAccount(oldAccount, newAccount, enforceSidHistory) if you would like to automate.

For example, you can enable PowerShell on your Windows Server hosting SharePoint and perform operation against SharePoint as described here, but SharePoint specific CmdLets we have for the 2010 and 2013 versions won't be available.

I don't have any SP 2007 now to test with, but something like the code below should work:

Set-ExecutionPolicy RemoteSigned -Force
$site = New-Object Microsoft.SharePoint.SPSite("http://sp2007")
$web = $site.OpenWeb()
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
# migrate only users of your old domain, so filter by prefix
$web.SiteUsers | ? {
  $_.LoginName -like 'domainold\*' 
} | % {
  $oldLogin = $_.LoginName
  $newLogin = $_.LoginName.ToLower().Replace('domainold\', 'domainnew\')
  $farm.MigrateUserAccount($oldLogin, $newLogin, $false) 
  • Yes, its related to my old Question SP 2007. I was thinking that i will enable PowerShell for SharePoint 2007 and then i will use PowerShell capabilities like iterating to migrate all the user accounts from old AD to new AD domain. So, its nor possible as i understand, right ?
    – SPBeginer
    Nov 14, 2014 at 14:10

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.