How to run stsadm -o migrate user command for multiple users

 Hi

Can anyone suggest me on how to run the  command "stsadm - o migrateuser -oldlogin XX\AA-newlogin YY\AA -ignoreidhistory"

in a bulk/batch for all users in a single shot  rather than running the command individually for each user.

Thanks in advance.

July 28th, 2015 11:02pm

Assume that you got old logins and new logins in a csv file format like this:

Old, New
a,a1
b ,b1
c,c1

You can use below PowerShell script to help you:

$Data = Import-Csv "C:\Users\MGOYAL\Documents\Book1.csv"
Set-Location "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\bin"
foreach($Item in $Data)
{
   .\stsadm.exe - o migrateuser -oldlogin $Item.Old -newlogin $Item.New -ignoreidhistory
}

Hope t
Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 1:16am

Hi Mohit,

Thanks for your response.

I tried this as you said and it is giving me an error and going to loop.

"command line error. Invalid Paramerter"

Thanks

July 29th, 2015 11:22am

Sorry, typo errors. Just remove the space between - and o. Or use below code:

$Data = Import-Csv "C:\Users\MGOYAL\Documents\Book1.csv"
Set-Location "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\bin"
foreach($Item in $Data)
{
   .\stsadm.exe -o migrateuser -oldlogin $Item.Old -newlogin $Item.New -ignoreidhistory
}

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 1:35am

Hi Mohit,

At first time itself I entered the correct code (As I know the syntax). 

So this is not working in my Dev environment, so I didn't run in Prod.

July 30th, 2015 10:06pm

Hi,

 Instead of using stsadm - o migrateuser command , you can use the SPFarm.MigrateUserAccount.

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

 More reference:

http://blog.sharepoint-voodoo.net/?p=68

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 10:43pm

Hi Jason,

I already tried this one. It gave me an error too.

The error was "Cannot add snappin..................already loaded"

Anyways thanks for your response.

July 30th, 2015 11:02pm

To solve such error, you can refer to the following articles:

http://sharepoint.smayes.com/2012/05/adding-a-powershell-snap-in/

http://solvedstack.com/questions/how-to-check-if-powershell-snap-in-is-already-loaded-before-calling-add-pssnapin

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 12:01am

I just noticed that, you are using -ignoreidhistory instead of -ignoreSidhistory.

I ran the script after modification and it works fine in my environment:

 Snap from book1:

Can you try after the same?

July 31st, 2015 2:53am

Hi Mohit,

It was was typo error while writing here, while testing I was using the correct sntax "ignoresidhistory"

Now I am receiving this error and this is going into infinite loop.

syntax error in argument: oldlogin.
syntax error in argument: newlogin.

I don't know what went on.

Thanks

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 10:21am

Hi Jason,

When I tried back again after changing the snapin check, it just gives the migration complete message (I was using the script from the link that you have shared).

But I don't see the changes happen.

Thanks

July 31st, 2015 10:24am

Can you check if the data is in the correct csv format, as I have mentioned. Pls note that you need to keep the headers same in csv file i.e 1 line. You can modify the data from 2nd line onwards.
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 11:11am

Everything is fine in the CSV file, when I run the powershell file (I save the code into ps1 file) it is giving error and going into infinite loop.
August 4th, 2015 10:36pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics