Republish all content types by Powershell


Today I’ll present an easy way to republish all the content types that are in a hub, this idea came because a customer wants to change the url of the App web, so I recreate it the App web, and the last step was to republish all the content type to restore the content of the portal as was before the change.

function Republish-HubContentTypes ($CTHubURL)
    #Get Content Type site and web objects
    $ctHubSite = Get-SPSite $CTHubURL
    $ctHubWeb = $ctHubSite.RootWeb

    #Check the site is a content type hub
    if ([Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher]::IsContentTypeSharingEnabled($ctHubSite))
        #Set up ContentTypePublisher object to allow publishing through the Content Type Hub site
        $spCTPublish = New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher ($ctHubSite)
        #Step through each content type in the content type hub
        $ctHubWeb.ContentTypes | Sort-Object Name | ForEach-Object {
                #Republish content type
                write-host "Content type" $_.Name "has been republished" -foregroundcolor Green
Republish-HubContentTypes –CTHubURL "ContentTypeHubURL"

Hope that helps!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s