Question

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
Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top