kwizcom banner advertisement

Publish Content Type in SharePoint using PowerShell

Content types that we create in one SharePoint site collection should be published from Managed metadata content type hub in order to make the content type available in all other site collections which consume Managed Metadata Service application.

How to publish from content type hub in SharePoint 2013?
To publish a content type from the content type hub site 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. 
    how to publish content type hub in sharepoint 2013
  • In content type settings page, click on "Manage publishing for this content type" link.
  • From this page, you can publish a content type by selecting "Publish" and clicking on "OK".
    publish content type sharepoint 2013 powershell
Also, If you make any changes to an existing published content type in content type hub site, you should republish the content type for the changes to take effect. Likewise, if you no longer want your content type to be available, you can unpublish the content type. (unblishing will not remove the content type in use from a subscriber sites). All published content types become available in site collections of consuming web application after the content type hub and content type subscriber timer jobs run.

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?
Here is the SharePoint PowerShell to publish content type. 
#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()
Publish Content Type in SharePoint using PowerShell Publish Content Type in SharePoint using PowerShell Reviewed by Salaudeen Rajack on 9:09 PM Rating: 5

2 comments:

  1. Hello Salaudeen,

    This is really good. Thank you.

    I wanted to find out if there is a script to publish ALL the content types and not just by groups.

    Thanks,
    Ricky

    ReplyDelete
    Replies
    1. Just remove the "Where" part.
      Instead of:

      $HubSite.RootWeb.ContentTypes | where { $_.Group -match $ContentTypeGroup } | ForEach-Object {
      Publish-ContentType $HubSiteURL $_.Name
      }

      use:

      $HubSite.RootWeb.ContentTypes | ForEach-Object {
      Publish-ContentType $HubSiteURL $_.Name
      }

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.