这是我到目前为止的脚本。我知道它很接近。我正在尝试使用csv文件更新项目列表。但是我不能更新Taxonomy字段。我试图避免要求guid和term ID运行。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Inquire
#Read the CSV file
$CSVData = Import-CSV -path "C:\files\testimport.csv"
#Get the Web
$web = Get-SPWeb -identity "http://site/Policies/"
$web.AllowUnsafeUpdates = $true;
Write-Host ( $web.Lists | Format-Table | Out-String)
#Get the Target List
$list = $web.Lists["Documents"]
$item = $list.GetItemById(4)
#$newTerm = "Test Data|074bbed9-da60-4a0c-9691-344436b5f96a"
$metadataField = ($item["Metadata"] -as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection])
#$metadataValue = New-Object -TypeName Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection -ArgumentList ""
#$metadataValue.PopulateFromLabelGuidPair("TestData");
#$metadataField.Add($metadataValue);
forEach ($line in $CSVData){
$item["Department"] = $($line.Department);
$item["Topics"] = $($line.Topics);
$item["History"] = $($line.History);
$metadataField = "Test Program|074bbed9-da60-4a0c-9691-344436b5f96a";
}
Write-Host ($item | Format-List | Out-String)
Write-Host ($metadata | Format-List | Out-String)
$item.Update();
#$list.Update();
答案 0 :(得分:0)
您需要获取对该术语的引用,然后使用TaxonomyField.SetFieldValue方法设置分类法字段的值。有关详细信息,请参阅此文章 - Updating SharePoint Managed Metadata Columns with PowerShell