Sunday, December 6, 2015

Publish Content Type in SharePoint using PowerShell

To publish a Content Type from the content type hub in SharePoint, browse to your content type hub site collection, Navigate to:

  • Site Settings >> Site Content Types 
  • Select the content type that you would like to publish. 
    sharepoint content type hub publish
  • In content type settings page, Click on "Manage publishing for this content type" link.
  • From this page, you can Publish the content type.
    publish content type sharepoint 2013 powershell
How to push changes from Content Type Hub to Site Collections immediately:
Once the content type is published it may take up to an hour for the subscribing Site Collections to get it. This is internally done by a timer job called "Content Type Subscriber" that is scheduled to run once an hour. To publish a content type and want to see them in your site collections immediately on-demand, go to:
  • Central Administration >> Monitoring > Review Job Definitions 
  • Pick the "Content Type Subscriber" job of your target web application and click on Run now 
  • Now, your content type should be available for use in subscribed sites.
    sharepoint powershell publish content type
Publish content type SharePoint 2013 using PowerShell
If the content type publishing activity is too frequent and repeating, we can automate it with PowerShell. Lets publish the content type in SharePoint using PowerShell.
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="http://intranet.crescent.com/CTypeHub"
$ContentTypeName="Sales Proposal v.1"

#call the function to publish content type
Publish-ContentType $HubSiteURL $ContentTypeName

How about Publishing all Content Types from a Content Type Group?
#Configuration Parameters
$HubSiteURL="http://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 
  }

To Trigger the Timer job using PowerShell:
$SubscriberWebAppURL="http://intranet.crescent.com/"

#Run the Content Type Subscriber timer job for a specific Web Application
$CTypeSubscriberTimerJob = Get-SPTimerJob "MetadataSubscriberTimerJob" -WebApplication $SubscriberWebAppURL
$CTypeSubscriberTimerJob.RunNow()



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...