我正在尝试在Managed Metadata列上为位于文档库中的文件夹中的文件设置属性值。我可以为其他元数据设置值,因为它们是文本字段。我相信我必须将它转换为另一种类型才能设置值。我尝试了各种方法,但似乎没有任何效果。 " Doc Type"是有问题的托管元数据列。
$files = Get-PnPFolderItem -FolderSiteRelativeUrl $folderRelativeUrl -ItemType File
foreach($file in $files)
{
write-output $file.Name
$file.Properties['Business Unit'] = $Global:BusinessUnit
$file.Properties['Customer Name'] = $Global:CustomerName
$file.Properties['Customer No'] = $Global:CustomerNumber
#$file.Properties['Doc Type'] = $Global:DocType
$file.Properties['Doc Type'] = $term.Name
$file.Properties['Job Name'] = $Global:JobName
$file.Properties['Job Number'] = $Global:JobNumber
$file.Properties['Opportunity Name'] = $Global:OpportunityName
$file.Properties['Opportunity No'] = $Global:OpportunityNumber
$file.Properties['Quote Name'] = $Global:QuoteName
$file.Properties['Quote ID'] = $Global:QuoteNumber
$file.Properties['System'] = $Global:System
$file.Update()
我正在使用此命令从术语库中获取术语
$term = Get-PnpTerm -TermGroup "Document Types" -TermSet Document -Identity $Folder -ErrorAction Ignore
$ Folder是我在学期商店中寻找的名称,例如:" Quote"。
答案 0 :(得分:1)
您可以考虑以下选项来设置分类值:
注意:假设
Doc Type
是单值分类法字段
选项1
通过CSOM API中的Taxonomy
,如下所示:
$files = Get-PnPFolderItem -FolderSiteRelativeUrl $folderRelativeUrl -ItemType File
$term = Get-PnpTerm -TermGroup $termGroup -TermSet $termSet -Identity $termId
#1. get taxonomy specific field
$ctx = $files.Context
$field = $files.ListItemAllFields.ParentList.Fields.GetByInternalNameOrTitle($fieldName)
$ctx.Load($field)
$ctx.ExecuteQuery()
$taxField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($ctx, $field)
foreach($file in $files)
{
write-output $file.Name
$taxField.SetFieldValueByTerm($file.ListItemAllFields,$term,1033) #2.update taxonomy field value
$file.ListItemAllFields['Job Name'] = $Global:JobName
$file.ListItemAllFields.Update()
#$file.Update()
}
选项2
通过PnP-PowerShell SetPnPTaxonomyFieldValue
cmdlet:
foreach($file in $files)
{
write-output $file.Name
Set-PnPTaxonomyFieldValue -ListItem $file.ListItemAllFields -InternalFieldName 'DocType' -TermId $term.Id
}