使用 PowerShell 在 SharePoint 中发布内容类型
我们在一个 SharePoint 网站集中创建的内容类型应从托管元数据内容类型中心发布,以使该内容类型在使用托管元数据服务应用程序的所有其他网站集中可用。
如何从 SharePoint 中的内容类型中心发布?
要从 SharePoint 中的内容类型中心网站发布内容类型,请浏览到您的内容类型中心网站集,然后导航到:
此外,如果您对内容类型中心网站中现有的已发布内容类型进行任何更改,则应重新发布该内容类型以使更改生效。同样,如果您不再希望您的内容类型可用,您可以取消发布该内容类型。 (取消发布不会从订阅者站点中删除正在使用的内容类型)。内容类型中心和内容类型订阅者计时器作业运行后,所有已发布的内容类型都将在使用 Web 应用程序的网站集中可用。
如何立即将更改从内容类型中心推送到网站集?
内容类型发布后,订阅网站集最多可能需要一个小时才能获取它。这是由名为“内容类型订阅者”的计时器作业在内部完成的,该作业计划每小时运行一次。要发布内容类型并希望立即按需在网站集中查看它们,请转到:
使用 PowerShell 发布内容类型 SharePoint
如果内容类型发布活动过于频繁且重复,我们可以使用 PowerShell 将其自动化。让我们使用 PowerShell 在 SharePoint 中发布内容类型。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Function to publish the content types
Function Publish-ContentType($HubSiteURL, $ContentTypeName)
{
#Get the objects from Parameters
$HubSite = Get-SPSite $HubSiteURL
$ContentType = $HubSite.RootWeb.ContentTypes | Where {$_.Name -eq $ContentTypeName}
#Check if the content type exists
if($ContentType -ne $null)
{
#Create a new content type publisher
$Publisher = New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher($HubSite)
#Publish-Unpublish
$Publisher.Publish($ContentType)
Write-Host "Published Content Type $ContentTypeName" -foregroundcolor Green
}
else
{
Write-Host "Content Type $ContentTypeName Not Found!" -ForegroundColor Red
}
}
#Configuration Parameters
$HubSiteURL="https://intranet.crescent.com/CTypeHub"
$ContentTypeName="Sales Proposal v.1"
#call the function to publish content type
Publish-ContentType $HubSiteURL $ContentTypeName
如何发布内容类型组中的所有内容类型?
以下是用于发布内容类型的 SharePoint PowerShell。
#Configuration Parameters
$HubSiteURL="https://intranet.crescent.com/CTypeHub"
$ContentTypeGroup="Crescent Templates"
#Get the content type hub
$HubSite = Get-SPSite $HubSiteURL
#Publish each content type from the group
$HubSite.RootWeb.ContentTypes | where { $_.Group -match $ContentTypeGroup } | ForEach-Object {
Publish-ContentType $HubSiteURL $_.Name
}
使用 PowerShell 触发计时器作业:
$SubscriberWebAppURL="https://intranet.crescent.com/"
#Run the Content Type Subscriber timer job for a specific Web Application
$CTypeSubscriberTimerJob = Get-SPTimerJob "MetadataSubscriberTimerJob" -WebApplication $SubscriberWebAppURL
$CTypeSubscriberTimerJob.RunNow()


