当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 在 SharePoint 中发布内容类型

作者:精品下载站 日期:2024-12-14 14:07:47 浏览:14 分类:玩电脑

使用 PowerShell 在 SharePoint 中发布内容类型


我们在一个 SharePoint 网站集中创建的内容类型应从托管元数据内容类型中心发布,以使该内容类型在使用托管元数据服务应用程序的所有其他网站集中可用。

如何从 SharePoint 中的内容类型中心发布?

要从 SharePoint 中的内容类型中心网站发布内容类型,请浏览到您的内容类型中心网站集,然后导航到:

  • 站点设置>>站点内容类型
  • 选择您要发布的内容类型。

    [玩转系统] 使用 PowerShell 在 SharePoint 中发布内容类型

  • 在内容类型设置页面上,单击“管理此内容类型的发布”链接。
  • 在此页面中,您可以通过选择“发布”并单击“确定”来发布内容类型。

    [玩转系统] 使用 PowerShell 在 SharePoint 中发布内容类型

此外,如果您对内容类型中心网站中现有的已发布内容类型进行任何更改,则应重新发布该内容类型以使更改生效。同样,如果您不再希望您的内容类型可用,您可以取消发布该内容类型。 (取消发布不会从订阅者站点中删除正在使用的内容类型)。内容类型中心和内容类型订阅者计时器作业运行后,所有已发布的内容类型都将在使用 Web 应用程序的网站集中可用。

如何立即将更改从内容类型中心推送到网站集?

内容类型发布后,订阅网站集最多可能需要一个小时才能获取它。这是由名为“内容类型订阅者”的计时器作业在内部完成的,该作业计划每小时运行一次。要发布内容类型并希望立即按需在网站集中查看它们,请转到:

  • 中央管理 >> 监控 > 审查职位定义
  • 选择目标 Web 应用程序的“内容类型订阅者”作业,然后单击“立即运行”
  • 现在,您的内容类型应该可以在订阅的网站中使用。

    [玩转系统] 使用 PowerShell 在 SharePoint 中发布内容类型

使用 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()

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯