I am using PnP.Powershell version 2.12.0.
I am trying to set values of two new managed metadata columns in a list using values from other columns. But I keep getting the following error:
Cannot bind parameter 'ListItem'. Cannot convert the "System.Collections.Generic.Dictionary
2[System.String,System.Object]" value of type | "System.Collections.Generic.Dictionary
2[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object,
| System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]" to type "Microsoft.SharePoint.Client.ListItem".
First I get the list item and the relevant fields as follows:
$colItems = (Get-PnPListItem -List $oList -id 236 -Fields “Orig Field 1”, “Orig Field 2”, “New Field 1”, “New Field 2”).FieldValues
This is technically a collection, so I used a forEach loop to get $oItem
. All the columns are managed metadata fields.
Then I tried two approaches to setting "New Field 1"
Set-PnPTaxonomyFieldValue -ListItem $oItem -InternalFieldName 'New Field 1' -TermID "ID String"
Where "ID String" is actually the GUID for the term, and
Set-PnPTaxonomyFieldValue -ListItem $oItem -InternalFieldName 'DEDiscipline' -TermPath = $NewValue
Where $NewValue
is in the form "Term Group|Term Set|Term"
Nothing works, and I keep getting the error above. I have gone into Entra ID admin and added additional permissions in Microsoft Graph and SharePoint, so I have Sites.FullControl.All
in both.
I have also tried using just Set-PnPListItem as follows:
Set-PnPListItem -List $oList -Identity $oItem -Values @{"New Field 1"=$NewValue}
I've pasted my API permissions below:
I use the following syntax for connecting:
Connect-PnPOnline -Url $SiteURL -ClientId <clientID> -Tenant <Domain>.onmicrosoft.com -Interactive