The get-spuser giving me following error

get-spuser You must specify a valid user object or user identity.

What to do next? I added foreach but that's not helping

foreach ($sc in $webapp.sites)
        # get the first instance of the user. when found, break out of the loop
        $cnUser = Get-SPUser -Identity $CurrentNetworkLogin -Web $sc.Url
        $cnUser = null; 
if ($cnUser)
    Move-SPUser -Identity $cnUser -NewAlias $FutureNetworkLogin -IgnoreSid -Confirm:$false

I even tried following but that's not working either. It give me Get-SPUser : You must specify a valid user object or user identity.

$claim = New-SPClaimsPrincipal -EncodedClaim "i:0#.w|NOV\asmith"
$user = Get-SPUser -Web http://inside.nov.sp -Identity $claim

2 Answers 2


Move-SPUser is a farm wide operation, so you do not need to loop through each site, although you do need a list of users you're migrating.

Get-SPUser expects the identity as it exactly matches, but passed in as a string. if using Windows Claims, it would be in the format of:

$user = Get-SPUser -Identity "i:0#.w|domain\jdoe" -Web https://siteUrl

You could loop through each Site Collection in the farm and retrieve all users, then using Excel or a similar tool, remove duplicates. From there, consume the identities from a CSV and perform the operation.

  • Trevor. either user profile is corrupt or something is messed up in 2010 farm. because this is what I am doing and it does not change the url for user whose network login changed to something else. thanks anyway. Commented Jun 17, 2016 at 15:14
  • Are you talking about the MySite URL? No, that won't change and that's expected. The only way to get it to change is by switching the MySite conflict detection method. That will, of course, change everyone's MySite to meet the new conflict detection chosen.
    – user6024
    Commented Jun 17, 2016 at 16:40
  • Trevor, this works only problem url for mysite not changing to new id. the funny thing is in TEST farm it works. Commented Jun 23, 2016 at 19:52

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

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).

Please check on below link.

Get-SPUser without specify a site collection

  • wait a minute. I have over 80 content databases. Which database I need to the query against? Commented Jun 13, 2016 at 13:31
  • Kindly check here...Specially under IDENTIFY Tab... krossfarm.com/?p=32
    – Hardik
    Commented Jun 13, 2016 at 13:38
  • Did you get it?
    – Hardik
    Commented Jun 13, 2016 at 14:05
  • 1
    There's no reason to query the SQL database (and you shouldn't).
    – user6024
    Commented Jun 13, 2016 at 14:45

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.