0

I have a column in a list that holds the Sharepoint ID of a user (as a string.) I have a script that takes that ID and grabs the SPUser object. I would like to update the value of another column as the actual SPUser object. The column is a single-select Person or Group. I've never had trouble creating new items thus far with this method, but it seems as though existing items behave differently.

This is my code so far:

### Sharepoint Connection ###

$sWebURL = 'http://sharepoint'
$sListName = "List"

$sWeb = Get-SPWeb $sWebURL

#Get the SPList object to retrieve the list
$sList = $sWeb.Lists[$sListName]

#Get items in this list and save them to an array
$sItems = $sList.Items | where {$_['ID'] -lt 287}

$sWeb.AllowUnsafeUpdates = $true
foreach($item in $sItems) {

    $temp =$web.EnsureUser($item['ID Column'])

    $item['User Column'] = $temp
    $item.update() 

}
$sWeb.AllowUnsafeUpdates = $false

$sWeb.Dispose()

It throws the error "Value does not fall within the expected range" on the line:

    $item['User Column'] = $temp

The line $temp.GetType() verifies that $temp is indeed a Microsoft.SharePoint.SPUser object.

Thoughts?

1

Assign SPFieldUserValue instead of SPUser.

Add Value to Person Field Programmatically

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.