Force a Publish of Content Types in a Content Type Hub using PowerShell

If like me, you find the process of republishing a number of content types in a Content Type Hub monotonous, the PowerShell script below can be used to quickly set the publish flag for all content types within a given Group Name.

function Publish-ContentTypeHub {
	param
	(
		[parameter(mandatory=$true)][string]$CTHUrl,
		[parameter(mandatory=$true)][string]$Group
	)

	$site = Get-SPSite $CTHUrl
	if(!($site -eq $null))
	{
		$contentTypePublisher = New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher ($site)
		$site.RootWeb.ContentTypes | ? {$_.Group -match $Group} | % {
			$contentTypePublisher.Publish($_)
			write-host "Content type" $_.Name "has been republished" -foregroundcolor Green
		}
	}
}

To call the script,

Publish-ContentTypeHub "[URL to CTH]" "[Group Name Containing Content Types]"

15 thoughts on “Force a Publish of Content Types in a Content Type Hub using PowerShell

  1. Amey Mulay

    The script worked like a charm !
    However, the only change was to remove the square brackets leaving the double inverted commas intact ! 🙂
    Many Thanks Once again !

    Reply
  2. Andrew

    Is it posible to unpublish a content type that previously has been deleted? Or I have to recreate the content type, publish it, unpublish it and finally delete it?

    Reply
    1. Terry Cornwell

      Andrew – sorry, it’s been a while since I checked in.

      I’d need to have a poke about into this one a bit. My first instinct is the the underlying GUID for the Content Types will be different so creating a new one then un-publishing would not work and it’s more likely you’re going to need a script to go through, find the content type by GUID and remove it. This does pose the question of what will you do with the information associated with that content type?

      If you’re still in need of help with this I’d reach out to the broader community through Twitter using #SPHelp. If you do get what you’re looking for let us know how you went on.

      Thanks
      Terry

      Reply
    2. Bryon Chan

      I had this issue on Sharepoint Online.

      I’ve just tried this, ie reprovisioning the content type (through powershell) with the same ContentTypeID, then going to “Managing publishing for this content type” and choosing “Unpublish”. And IT WORKED!

      Reply
  3. Michael Boggs

    Not able to get this to work with SharePoint 2013 online (office 365). I think the “New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher” doesn’t work in the cloud.

    New-Object : Cannot find type

    [Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher]: make

    sure the assembly containing this type is loaded.

    At line:1 char:1

    + New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentExcepti

    on

    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewOb

    jectCommand

    Reply
      1. Terry.Cornwell Post author

        Hi Jussi,

        You’re correct. This is strictly for an on-prem, service side solution

        Thanks for reading
        Terry

        Reply
      2. Salil Shah

        It has been 2 yrs now.. Is Content Type publishing available via CSOM? We want to publish content tyep in SharePoint online via CSOM

        Reply
        1. Terry Cornwell

          I’ve not looked into this for quite a while however, SharePoint 2013’s REST API provides a level of access to the Content Types at the SPWeb level. I would expect there’s potential here to exploit this within a Content Type Hub to force a republish. If you find anything let me know and equally, if I get around to reviewing this I’ll post an update.

          Also, see Travis’s method below.

          Reply
    1. Terry.Cornwell Post author

      Hi,

      This won’t work with O365. This is a server side only script. The ContentTypePublisher isn’t available through CSOM. I’ll get around to providing an update one day (when work demands allow me!)

      Thanks for commenting
      Terry

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *