Mar 01 2017 08:26 PM
I am trying to upload document to SharePoint Online along with meta data using PowerShell CSOM
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password1) $Context.Credentials = $Creds #Retrieve list $DocLibName = 'Documents' $List = $Context.Web.Lists.GetByTitle($DocLibName) $Context.Load($List) $Context.ExecuteQuery() $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation $FileCreationInfo.Overwrite = $true $FileCreationInfo.ContentStream = $FileStream $FileCreationInfo.URL = 'test123.pdf' $Upload = $List.RootFolder.Files.Add($FileCreationInfo) $listItem = $Upload.ListItemAllFields $listItem["Title"] = 'Title' $listItem["PNo"] = '1234' $listItem["Desc"] = 'Some Text' ################ Set Value for Managed Metadata Column ########## $listItem.Update() $Context.Load($Upload) $Context.ExecuteQuery()
I have issue when try to set value of Managed Metadata column column. Tried following approaches and not working. Error - Value is not in expected range
$listItem["ManagedMetaDataColumn"] = 'f31984fe-f02b-4354-ac6a-cdaa148c1357'
and other approach for which error is - Method is not supported
$fieldPDT = $list.Fields.GetByInternalNameOrTitle("ManagedMetaDataColumn") $Context.Load($fieldPDT) $Context.ExecuteQuery() $taxField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($context, $fieldPDT) $taxFieldValueCol = New-Object Microsoft.SharePoint.Client.Taxonomy.TaxonomyFieldValueCollection($context, $term , $taxField) $taxField.SetFieldValueByValueCollection($listItem, $taxFieldValueCol)
My question is can we specify "Managed Metadata" column when uploading the document. If yes, any help?
Mar 01 2017 10:51 PM
Mar 02 2017 01:21 PM - edited Mar 02 2017 02:12 PM
Mar 02 2017 01:21 PM - edited Mar 02 2017 02:12 PM
Verified GUID and tried but same issue.
If I try to get reference of list item and update mata data, others columns are populated but not managed matadata column.
This time, I don't have error
$Context = CreateConnection #Retrieve list $DocLibName = 'Documents' $List = $Context.Web.Lists.GetByTitle($DocLibName) $Context.Load($List) $Context.ExecuteQuery() $qry = New-Object Microsoft.SharePoint.Client.CamlQuery $items = $List.GetItems($qry) $Context.Load($items) $Context.ExecuteQuery() foreach($item in $items) { try { $item["ManagedMetaDataColumn"] = "f31984fe-f02b-4354-ac6a-cdaa148c1357" $item["New"] = '12344' $item.Update() $Context.ExecuteQuery() } catch [Exception] { $strException = $_.Exception + $_.ErrorDetails + $_.ScriptStackTrace + $_.ErrorDetails + $_.Exception } }
Mar 19 2017 02:25 PM
For other, I resolved this by using PnP - Powershell.
You can use either Set-PnPListItem OR Set-PnPTaxonomyFieldValue