我找到了为什么 webpart 仍然是灰色的。我只需要使用SPField.Update
带有参数的方法$true
。
以下是希望使用 sharepoint powershell 解决此问题的代码示例:
$web= Get-SPWeb your.sharepoint.site
$WikiCategory = "YourCategory"
$ColumnName = "Wiki Categories"
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termStores = $session.TermStores
$SspId = $termStores[0].Id
function GetTermSetId($termStores)
{
foreach ($termstore in $termStores[0].Groups)
{
$TermSetId = $termstore.TermSets[$WikiCategory].Id
return $TermSetId
}
}
$TermSetId = GetTermSetId($termStores)
$contentType = $web.ContentTypes["Enterprise Wiki Page"]
$column = $web.Fields[$ColumnName]
$fieldLink = New-Object Microsoft.SharePoint.SPFieldLink($column) $contentType.FieldLinks.Add($fieldLink)
$contentType.Update()
$column.SspId = $SspId
$column.TermSetId = $TermSetId
$column.Required = $false
$column.EnforceUniqueValues = $false
$column.Group = "Custom Columns"
$column.Update($true)
$web.Update()
$web.Dispose()