You might have seen the similar script in other blogs for migrating users / groups. Here is my contribution for the same requirement. You can use this script for migrating bulk AD users and AD groups in a single shot. I have created this script to read the information from CSV file. You can find the actual script and two sample CSV files below of this post. My customer’s scenario was, they have upgraded their SharePoint 2007 to SharePoint Server 2010 but their domain changed in SharePoint Server 2010 so they have to update AD user and group information in the SharePoint databases by running the MigrateUserAccount & MigrateGroup method.
SPFarm.MigrateUserAccount is same as the STSADM migrateuser command that we all were familiar. This method migrate user account in SharePoint Foundation to a new login name and binary ID. If an entry for the new login name already exists, it is deleted to allow this change. The following entities are updated in the entire server farm: site collection users in the UserInfo tables, people lists, and security policies.