4

I'm facing an issue while moving a user.

I'm first retrieving the user object:

$Site = Get-SPSite "https://mysite.mydomain.com"
$Web = $Site.OpenWeb()
$User = $Web.EnsureUser("domain\userid")

And then I'm executing the below to migrate the user:

Move-SPUser -Identity $User -newalias "domain\userid" -IgnoreSID

But when I do so, I get an error:

Move-SPUser : The given key was not present in the dictionary. At line:21 char:1 + Move-SPUser -Identity $User -newalias "domain\userid" -IgnoreSID + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (Microsoft.Share...PCmdletMoveUser: SPCmdletMoveUser) [Move-SPUser], KeyNotFoundException + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletMoveUser

3

1 Answer 1

6

When switching from one AD-environment to another, you sometimes end up with users who don't get imported correct. You see them when they don't have first name and last name when they are logged in to SharePoint. They have \ visible instead.

But let's start from the beginning and migrate the users with the following command:

STSADM –o migrateuser –oldlogin OLDDOMAIN\user1 –newlogin NEWDOMAIN\user1 –ignoresidhistory

After that you need to run a full user profile synchronization. When this is done, continue and see which users where not imported correct.

# Clean up accounts that is not imported correctly

$upsa = Get-SPServiceApplication | Where-Object {$_.TypeName -like "User Profile Service Application"}

# List all user accounts that is not imported correctly
Set-SPProfileServiceApplication $upsa -GetNonImportedObjects $true

# Remove user accounts not imported correctly 
# Uncomment line below to run
Set-SPProfileServiceApplication $upsa -PurgeNonImportedObjects $true

# Run a full User Profile Service Syncronisation, and make sure users
# end up in Profile database.
# If not, users who log in will create new NonImportedObject accounts

This might have to be repeated several times, especially if you're in a live environment where users login during the day. Eventually these orphan user profiles will disappear. If you have a lot of users, the script will take a lot of time - so please be patient unless you get an error from PowerShell. Good Luck!

Your Answer

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

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