How to republish all the content types in a Content Hub using Powershell in SharePoint 2010/2013/2016?

Hello SharePointers,

Below are the Powershell commands to republish all the content types in a Content Hub using Powershell.

Add-PSSnapin microsoft.sharepoint.powershell
function RepublishHubContentTypes ($HubURL)
{
$HubSite = Get-SPSite $HubURL
$Web = $HubSite.RootWeb

#Check the site is a content type hub
if ([Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher]::IsContentTypeSharingEnabled($HubSite))
{
#Set up ContentTypePublisher object to allow publishing through the Content Type Hub site
$CTPublish = New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher (HubSite)

#Step through each content type in the content type hub
$Web.ContentTypes | Sort-Object Name | ForEach-Object {

if ($CTPublish.IsPublished($_))
{
$CTPublish.Publish($_)
write-host “Content type” $_.Name “has been republished” -foregroundcolor Green
}
else
{
write-host “Content type” $_.Name “is not a published content type”
}
}
}
else
{
write-host $HubURL “is not a content type hub site”
}

$Web.Dispose()
$HubSite.Dispose()
}

Happy SharePointing Folks 🙂

Leave a Reply

Your email address will not be published.