Thursday, August 27, 2015

One problem with Set-SPUser cmdlet

When you use Set-SPUser cmdlet which sets user properties, e.g. email:

Set-SPUser -Identity "domain\username" -Web http://example.com -Email user@example.com

you may get the following error message:

You must specify a valid user object or user identity

This error may be shown if your web application uses claims-based authentication, but you specified username in command line arguments in regular Windows format: domain\username. In order to avoid this error try to use claims format for username:

Set-SPUser -Identity "i:0#.w|domain\username" -Web http://example.com -Email user@example.com

It should fix the problem.

8 comments:

  1. This solved my problem! Thanks!
    (also applies for the Get-SPUser cmdlet)

    ReplyDelete
  2. Hi,

    what about if I want to sync Email with AD ?

    Set-SPUser -Identity "i:0#.w|domain\username" -Web http://example.com -SyncFromAD


    Set-SPUser : Cannot get the full name or e-mail address of user "i:0#.w|XXX\XXX".

    ReplyDelete
  3. Franck,
    can it be so that in your case you need to use user name in "domain\username" (not claims) format

    ReplyDelete
  4. Hello Alexey,

    Manually updating user properties, like Email, is ok using your command below
    --> Set-SPUser -Identity "i:0#.w|domain\username" -Web http://example.com -Email user@example.com

    But what if I want to change Email property from AD using the
    -SyncFromAD ?

    Thanks

    ReplyDelete
  5. and you sure that email is specified in AD for the user which you try to update?

    ReplyDelete
  6. ok, asked just in case) as I didn't faced with this issue by myself just may suggest to continue googling about this problem and if you will find solution it would be great if you will share it here

    ReplyDelete
  7. Excellent post! I was getting exactly the same issue and had no idea how to fix it. The trick worked like charms.

    ReplyDelete