此代码使用新值覆盖所有旧值;我需要一个代码来附加旧值。
<Code For Termset>
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy")
$site = Get-SPSite http://invi28apps9c
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termStore = $session.TermStores["Managed Metadata Service"]
$group = $termStore.Groups["KB"]
$termSet = $group.TermSets["IPS Document type"]
$terms = $termSet.GetTerms(100)
$term = $terms | ?{$_.Name -eq "Docset"}
$web = Get-SPWeb http://invi28apps9c/DemoTeamSite
$list = $web.Lists["KBDocument"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000
$caml = "<Where>
<Eq>
<FieldRef Name='DocIcon'/>
<Value Type='Computed'>.zip</Value>
</Eq>
</Where>"
$query.Query = $caml
do
{
$listItems = $list.GetItems($query)
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach($item in $listItems)
{
$spItem = [Microsoft.SharePoint.SPListItem]$item;
$taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$spItem.Fields["Document Type"]
$taxField.SetFieldValue($spItem,$term)
$spItem.Update()
}
}
while ($spQuery.ListItemCollectionPosition -ne $null)
答案 0 :(得分:0)
当您访问该字段的值时,您应该收到一个TaxonomyFieldValueCollection对象。此对象具有Add()
方法,您可以使用该方法向其添加术语。
$value = $spItem["Document Type"]
$value.Add($term)
$spItem["Document Type"] = $value
$spItem.Update()