1

I try to update a SharePoint Online people field (in a doc list), from PowerShell.

Here's the code:

$properties = $Upload.ListItemAllFields;
$context.Load($properties)
$properties["CLT"] = $File.Name.Substring(0,10)
$spcompte = Get-SPOUser -Site https://xxxx.sharepoint.com/ -LoginName "xxxx@xxxx.onmicrosoft.com" 
$properties["ACCOUNT"] = $spcomte
$properties.Update()

No problems with a $spcompte.displayname, it shows the correct user,

But $properties["ACCOUNT"] = $spcomte just returns the following :

Exception calling "ExecuteQuery" with "0" argument(s): "Des données non valides ont été utilisées pour mettre à jour l'élément de liste. Le champ que vous essayez de mettre à jour est peut-être en lecture seule." At C:\Sharepoint PowerShell.ps1:50 char:1 + $Context.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ServerException

Google translate for the error:

Invalid data was used to update the list item . The field you are trying to update may be read only.

Any idea? I see a lot of stuff about Get-SPUser for SharePoint server, but nothing for Online.

  • I would just try setting it with their email address and let it do the validation and everything normally, rather than trying to pass in an object. – Eric Alexander Jun 26 '15 at 13:55
0

I have the same problem. I found the solution at last, so I would like to share with you if it helps

$SiteUrl = "Your site URL"

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 

$Item["Title of column"] = $Context.Web.EnsureUser("e-mail of user") 
| improve this answer | |
0

Using the below PowerShell script, we can update the people picker column in SharePoint online:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/sites/pmo"
$ListName="Projects"
$FieldName= "ProjectMembers" #Internal Name
$ListItemID="25"
$UserIDs=@("salaudeen.rajack@crescent.com","Charles.jonathan@crescent.com","mark.jones@crescent.com")

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the List & Item to update
$List = $Ctx.Web.lists.GetByTitle($ListName)
$ListItem = $List.GetItemById($ListItemID)
$Ctx.Load($ListItem)
$Ctx.ExecuteQuery()

#Resolve each user ID and get the User Objects
$UserValueColl = @()
ForEach($UserID in $UserIDs)
{
    #Get the User to Update
    $SPOUser = $Ctx.Web.EnsureUser($UserID)
    $Ctx.Load($SPOUser)
    $Ctx.ExecuteQuery()

    If($SPOUser -ne $Null)
    {
        $SPOUserValue = New-Object Microsoft.SharePoint.Client.FieldUserValue
        $SPOUserValue.LookupId = $SPOUser.id
        $UserValueColl += $SPOUserValue
    }
}

IF($UserValueColl.length -gt 0)
{
    $UserValueCollCollection = [Microsoft.SharePoint.Client.FieldUserValue[]]$UserValueColl
    #Update the Multi-People picker column
    $ListItem[$FieldName] = $UserValueCollCollection
    $ListItem.Update()
    $Ctx.ExecuteQuery()
    Write-Host -f Green "List Item has been updated!"
}

Reference URL:

SharePoint Online: Read / Update Person or Group Field (People Picker) Values using PowerShell

| improve this answer | |

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.