3

I am going to migrate users with Move-SPUser. To do this, I am getting the user first:

$user = Get-SPUser -Identity $adAccount -web https://sharepoint/site-collection

The moving them:

Move-SPUser –Identity $user –NewAlias $NewAccountName -IgnoreSID -Confirm:$false

It appears when I get a user, I have to point to a specific site collection; whereas the actual move cmd doesn't reference any site collection. The problem I am having is we have 22 site collections and I would rather not have to traverse all the site collections to find the user first to fill the $user variable. I tried using:

Move-SPUser –Identity "domain\user-account" –NewAlias $NewAccountName -IgnoreSID -Confirm:$false

but it caused an error:

Get-SPUser : You must specify a valid user object or user identity.

I guess if I have to go through each site collection first I will, but I have 7,000 users to migrate and it seems really inefficient to have to do that.

Also, if that is the only way the user information list in the site collection gets updated (because the $user object somehow holds a reference to the site collection) that would make it necessary for me to do it because the user might exist in more than one site collection.

Hope that makes sense and any advice is appreciated.

1

You may also consider using a SQL query for this. It is minimally invasive, and quite effective.

[Use] ContentDatabaseName
SELECT tp_SiteId,tp_Login FROM UserInfo (NoLock)

From there, export the data to a CSV file and trim the duplicates (tp_Login column). Add a 3rd column in the CSV file for the new identity, then run:

$csvPath = 'C:\fileName.csv'

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

Import-Csv $csvPath -Header tp_SiteId,tp_Login,NewIdentity |
ForEach-Object {
   Write-Host $site.Url
   $site = Get-SPSite -Identity $_.tp_SiteId
   $user = Get-SPUser -Identity $_.tp_Login -Web $site.Url
   Write-Host $user
   Write-Host $_.NewIdentity
   Move-SPUser -Identity $user -NewAlias $_.NewIdentity -IgnoreSID -Confirm:$false
   $site.Dispose()
}

Unfortunately, the SSOM isn't well suited to this task, and making this RO T-SQL query is very low risk (more so if you can simply backup and restore the databases temporarily to another SQL Server/different name and make your query).

  • Thanks Trevor! Quick question, how reliable is the move-spuser for converting user permissions? I was asked to document all permission prior to and after the move to do a comparison. That is a huge number of data points. Do you think this necessary? – steveareeno Dec 23 '15 at 17:16
  • No, really not necessary. If you have a UPA, just make sure the account has Full Control over the UPA. – Trevor Seward Dec 23 '15 at 20:40
4

The users are stored per SiteCollection, so there will no other way as to iterate through all of them.

  • 1
    Ok. Thanks. So to expand a little, if I grab user A from site collection A and move him, what happens to his reference in the user information list in site collection B? The move cmd deletes the old user account in the user profile right after the move. Does site collection B get updated by the sync timer job? – steveareeno Dec 22 '15 at 14:16
0

I just want to expand on Leopold's answer, based on some testing I did. I had a user who was in multiple site collections. I used the following to get a reference to the user and move the user to the new account:

foreach ($SiteCollection in $webapp.sites)
{
    try
    {
        # get the first instance of the user. when found, break out of the loop
        $user = Get-SPUser -Identity $adAccount -web $SiteCollection.Url
        break
    }
    catch
    { 
        $user = null; 
    }
}

if ($user)
{
    Move-SPUser –Identity $user –NewAlias $NewAccountName -IgnoreSID -Confirm:$false
}

I went to each site collection's user information list, found the user, and clicked on the user name. Each one took me to the new account user profile. I also verified the (hidden) "account" column value was updated in each of site collection user information lists. So bottom line, you only need to get the user from one site collection and when you use Move-SPUser, all the other site collections will have the updated information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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