When you add or update a listitem, only one lookup column is updated and some other normal fields, depends on (maybe?) the name of the field.
The operation should save the value of every field passed in the Values hashtable
It only updates some fields until it gets the lookup field. After that, no other value is updated.
Same with Set-PnpListItem.
Current workaround: Add-PnPListItem, then a Set-PnPListItem for each lookup value.

"Detalle" column and "Cosa" column are lookups. "Cal" is a number field.
I couldn't determine why some fields are updated with some lookups (like Cosa let Cal get value but not Detalle. And Detalle and Cal didn't work together). I thing it may be some alphabetical order, because in previous tests Title never got value. Another thing: ContentType parameter didn't affect. Same behavior with it, and without.
For each item, these are the pnp commands ran.
Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 1"; "Detalle" = "5"; "Cosa"="3"; } -ContentType "Elemento"
$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 2"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; "Cosa"="3"; "Cal"="2.1";}
$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 3"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; "Detalle" = "5"; "Cal"="2.1";}
$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 4"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; }
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; }
$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 5"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; "Cal"="2.1";}
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; }
$item = Add-PnPListItem -List "Lista3" -Values @{"Title"="Tercera 6"; } -ContentType "Elemento"
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Detalle" = "5"; }
Set-PnPListItem -List "Lista3" -Identity $item.Id -Values @{"Cosa"="3"; "Cal"="2.1";}
2.22.1801.0
I am seeing similar behavior to my existing PowerShell script which was working fine with earlier version of PnP PowerShell. Even I tested with version 2.23.1802.0 but still same issue.
Hi,
I experience the same problem, but with Add-PnPFile. v2.22.1801.0.
But how do I get the ID of the just created file?
Greets,
Peter
@Peter-De-Meester I had to take id with this:
$ctx = Get-PnPContext
$newFile = Add-PnPFile -path $file.FullName -folder "Shared documents"
$id = $newFile.ListItemAllFields
$ctx.Load($id)
$ctx.ExecuteQuery()
The you have the $id which you can use to:
set-pnplistitem -list <listnama> -identity $id
Hope this helps :)
After confirming this problem with the latest version, I stepped back until I found one that appears to work, which is 2.19.1710.1. All versions since appear to be broken in some way for Add-PnpListItem.
Looking at the commit history, I see item handling was refactored on Nov 19. Possibly a bug introduced here.
Hi Kallejar & NoahStahl,
Thanks both for the comment. While waiting for a solution, I'll use the workaround.
Greets,
Peter
I'll have a look at it.
I found the bug and will work on an update
I fixed the bug and merged it with the dev branch.
Most helpful comment
I fixed the bug and merged it with the dev branch.