2

We need to insert a bulk data from MS Excel into SharePoint lists. We committed this using Powershell. Almost everything straightforward, until we found a stoper with People columns.

From Excel people info are comming something like: Claire@mycompany.com, but SharePoint requires a valid SPFieldUserValue.

If I tried this: (it fails)

$item["MyPerson"] = $excelRow.MyPerson # this not works because is an Email.

I need something like:

$userValue = FindUserValueByEmail -email $excelRow.MyPerson
$item["MyPerson"] = $useValue
1

I'm guessing you are using SSOM, if so you probably also have a $web object for the SPWeb, and so you could try:

$user = $web.EnsureUser($excelRow.MyPerson)
$item["MyPerson"] = $user.ID

I don't think you need to assign an actual SPFieldUserValue object, but if you have to try this:

$item["MyPerson"] = New-Object Microsoft.SharePoint.SPFieldUserValue($web, $user.ID, $user.LoginName)

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.