pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Set-PnPListItem does not accept array as value to set multiple Person/Group #1103

Closed colonelclaypoo closed 6 years ago

colonelclaypoo commented 6 years ago

Reporting an Issue or Missing Feature

Set-PnPListItem does not seem to accept array variables passed to the hastable in the value position.

Expected behavior

Specifying muliple values for a PersonField works if enclosed in double quotes and separated by commas. I would expect the same to work for a array-variable that is passed as the value for the PersonField in the hashtable.

Actual behavior

This code works: Set-PnPListItem -List $list -Values @{$Column1= "test1@contoso.com","test2.contoso.com"}

This code does not work: Set-PnPListItem -List $list -Values @{$Column1= $users}

Steps to reproduce behavior

I'm not sure if it's due to the way the $users array was created.

Here's how I needed to retrieve the values that ended up existing in the array: $users = ($SiteSecurityGroups | Where-Object {$_.Title -eq "Members"}).Users | Where-Object {$_ -notlike "*ext*"}.

For reference, $SiteSecurityGroups contains values retrieved with Get-SPOSiteGroup -Site $site. $users should contain the users' email addresses that are retrieved from a site collection security group called "Members" and that do not contain "ext" in the email address name.

I hope this makes sense to you.

$user -is [system.array] evaluates to True so it should be an array. However, Set-PnPListItem does not accept it. The error message I get is:

`Set-PnPListItem : The specified user could not be found (translated from German). In Zeile:1 Zeichen:92

Thanks for your input.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

ModuleType Version ExportedCommands


Binary 2.17.1708.1 {[Add-PnPContentType, Add-PnPContentType], [Add-PnPCo...
Binary 2.16.1706.1 {[Add-PnPContentType, Add-PnPContentType], [Add-PnPCo...
Binary 2.15.1705.0 {[Add-PnPContentType, Add-PnPContentType], [Add-PnPCo...
Binary 2.12.1702.0 {[Add-PnPContentType, Add-PnPContentType], [Add-PnPCo...
Script 2.11.1701.1 {[Get-PnPWebTemplates, Get-PnPWebTemplates], [Get-PnP...

How did you install the PnP-PowerShell Cmdlets?

erwinvanhunen commented 6 years ago

I used a somewhat different approach, which worked for me:

$users = (Get-PnPGroup | Where-Object {$_.Title -eq "Members"}).Users | Where-Object {$_ -notlike "*ext"} | select -ExpandProperty Id
Set-PnPListItem -List $list -Values @{$columnNameToAdd = $users}

Notice that I am adding the users by id.

colonelclaypoo commented 6 years ago

Thanks for reply. That works for me.

holylander commented 5 years ago

select -ExpandProperty Id

in case that this information may become helpful to any: I also had to convert that UserId into a string, in order to get the Add-PnPListItem

drullo commented 4 years ago

This does not work for me. I am unable to set multiple values to a Person/Group column. It only writes the first value in the list of values.

holylander commented 4 years ago

This does not work for me. I am unable to set multiple values to a Person/Group column. It only writes the first value in the list of values.

Do a rest query and inpect how the data related to that column is formatted ( when it has more that one value ), then mimic that format when doing the update. Should work