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:
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:
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.
How about Publishing all Content Types from a Content Type Group?
Here is the SharePoint PowerShell to publish content type.
To Trigger the Timer job using PowerShell:
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.
- 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".
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.
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()
Hello Salaudeen,
ReplyDeleteThis 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
Just remove the "Where" part.
DeleteInstead of:
$HubSite.RootWeb.ContentTypes | where { $_.Group -match $ContentTypeGroup } | ForEach-Object {
Publish-ContentType $HubSiteURL $_.Name
}
use:
$HubSite.RootWeb.ContentTypes | ForEach-Object {
Publish-ContentType $HubSiteURL $_.Name
}
Hello Salaudeen,
ReplyDeleteThank you for this great script.
I wanted to find out if there is a script to publish the content types for SP online using Powershell?
Thanks,
JS
Unfortunately, No! We can't publish content types in SharePoint Online using PowerShell as of today. There is a user voice raised here: https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/15147111-allow-publishing-of-content-type-hub-content-types
Delete