SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a client requirement to move from Classic to Claims. I'm currently utilizing some PowerShell from

$webApp =
$farm = get-SPFarm
$wa = get-SPWebApplication $webApp
$site = get-SPSite $webApp
$web = $site.OpenWeb()
foreach ($user in $web.AllUsers) {
   $newuser = $user
   $newuserLoginName = “”
   if ($newuser.LoginName.StartsWith(“i:0#.w|”))
      ! $newuserLoginName = $user.LoginName.Substring(7)
   $user = $newuser
   $farm.MigrateUserAccount($user.LoginName, $newuserLoginName, $false)

Unfortunately every time I try to run it I get the following

Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to like a variable or a property. At C:\Users\user\Desktop\claims.ps1:12 char:22 + ! $newuserLoginName = <<<< $user.LoginName.Substring(7) + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : InvalidLeftHandSide

Any idea on what could be wrong?


Sorry forgot to paste the script in question in originally!

share|improve this question
Umm... Could you please post the full line of the script that causes the error (you could even post the whole script if it is not too long). – SPArchaeologist Nov 23 '12 at 11:50
Sorry that's done for you now! – SolidCactus Nov 23 '12 at 11:55
Thanks, didn't notice that the link was just the same with that trackback part at the end. Ok, leave me some time to see if I notice anything strange. – SPArchaeologist Nov 23 '12 at 12:13
up vote 0 down vote accepted

I may be wrong but I suppose that the exclamation mark on the

!$newuserLoginName = $user.LoginName.Substring(7)

line should just be a refuse (or at last it doesn't match any syntax I am aware of).

If you are on a test environment or are otherwise sure that you won't damage your system with a wrong comand, I would try to replace the if with:

if ($newuser.LoginName.StartsWith(“i:0#.w|”))
   $newuserLoginName = $user.LoginName.Substring(7)

The if should simply remove the "claim specific part" from the login name, so I would assume the original blog post intended it this way.

That said, know that I have never done this before and are only trying to spot an error in the powershell code. I don't know if that code will actually do what promised, so use that at your risk (or wait some more expert other user to confirm the behaviour).

share|improve this answer
Thanks man. Let me test this on the test environment and see what it comes back with! – SolidCactus Nov 23 '12 at 12:47
Yeah, I don't know if this could be it, but since the error message points to that line and basically say "you cannot assign the value to that, I don't know what to do", I would give it a try. For what I know that line would mean "assign the value to the negation of the variable xyz", which IMHO doesn't make sense. – SPArchaeologist Nov 23 '12 at 12:50
Thanks that was the ticket! Very much appreciated! – SolidCactus Nov 23 '12 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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