0

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)
{
    try
    {
        # get the first instance of the user. when found, break out of the loop
        $cnUser = Get-SPUser -Identity $CurrentNetworkLogin -Web $sc.Url
        break
    }
    catch
    { 
        $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

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. – Kevin Short Jun 17 '16 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. – Trevor Seward Jun 17 '16 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. – Kevin Short Jun 23 '16 at 19:52
-3

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

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? – Kevin Short Jun 13 '16 at 13:31
  • Kindly check here...Specially under IDENTIFY Tab... krossfarm.com/?p=32 – Hardik Jun 13 '16 at 13:38
  • Did you get it? – Hardik Jun 13 '16 at 14:05
  • 1
    There's no reason to query the SQL database (and you shouldn't). – Trevor Seward Jun 13 '16 at 14:45

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.