Set-PnPListItem should set users in list fields but I can't get the format right. Usually, I would set it like documented, i.e. @{"PersonField" = "user1@domain.com","21"}.

However, in my case each list item could have different fields to be updated. Therefore, the hashtable might contain different key-value-pairs for each list item. That's why I need to be able to pass -Value the hashtable itself.

Now, trying to pass a hashtable like this results in ' The specified user could not be found.' :

enter image description here

It seems the error is not due to the hashtable containing multiple pairs. I tried a hashtable with only one pair and the error is the same. Could it have to do with the values not being treated as strings?

Do you have any idea how I can get it to work? Thanks a lot.


So by trial and error I found a workaround but I have no idea why it has to be that way.

The way I populate the hashtable seems to make a difference. What's not working was:

EDIT: So by trial and error I found a workaround but I have no idea why I have to do what I have to do for it to work.

Doing the following does not work with Set-PnPListItem -List $list -Identity [...] -Values $updates:

$updates = @{} if ($null -ne $currentSiteOwners) { $updates.Owner = $currentSiteOwners() }

However, using the .ToLower() method makes it work:

$updates = @{} if ($null -ne $currentSiteOwners) { $updates.Owner = $currentSiteOwners.ToLower() }

The fact that the .ToLower()method converts the id's contained in $currentSiteOwners to lower case cannot be the reason as they are not letters to begin with. The method must be performing some kind of string transformation that -Valueultimately accepts.

Anyone any clue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.