SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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'm trying to get this to work in PowerShell:

$spListItem[$ppField] = "domain\username"
$spListItem.Update()

This gives me the following error:

Exception calling "Update" with "0" argument(s): "Invalid data has been used to update the list item. The field you are trying to update may be read only."

I know by that SharePoint is expecting something like 3;domain\username

What's the easiest way to get this? I hope I don't have to iterate over the full SPUserCollection.

share|improve this question
up vote 11 down vote accepted

Here is the solution:

 [Microsoft.SharePoint.SPUser]$spuser =    $spWeb.EnsureUser("domain\username")         
 $spListItem[$newSMTName] =  $spuser  
 $spListItem.Update()
share|improve this answer

You could also use the following

$spUser = Get-SPUser -Identity "domain\username" -Web $web;
$spListItem[$ppField] = $spUser;
$spListItem.Update()
share|improve this answer

Your Answer

 
discard

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.