Friday, 19 November 2010

Republish all hub content types in SharePoint using PowerShell

The idea for this script came in as a request from an anonymous comment I received yesterday on an earlier post showing how to push changes from a content type hub site to site collections using PowerShell.

The script in this article steps through each content type in a content type hub and republishes any that have been previously published. Once you specify the content type hub URL, the script performs the following tasks:

  • Checks to see if the URL specified is a content type hub site
  • Enumerates through each site content type in the hub and:
    • Checks if the content type has been previously published
    • If it has, republish it and write a success message to the console
    • If it hasn’t, write a message to the console confirming it is not a published content type

To use it, run this script first:

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 {
            #Has the content type been published?
            if ($spCTPublish.IsPublished($_))
                #Republish content type
                write-host "Content type" $_.Name "has been republished" -foregroundcolor Green
                write-host "Content type" $_.Name "is not a published content type"
        write-host $CTHubURL "is not a content type hub site"
    #Dispose of site and web objects

Once run, you can call the script by typing the following command:

Republish-HubContentTypes –CTHubURL <ContentTypeHubURL>

For example, type the following command to republish all content types in a hub site with the URL http://portal/sites/CTHub:

Republish-HubContentTypes -CTHubURL http://portal/sites/CTHub

An example output from the script is shown below:



  1. this is perfect for what i needed to do today, thank you for posting it.

  2. It's a pleasure Jeff - thanks for saying "thanks" :)

  3. Hi Phil,

    I am trying to excute the above the script but iam getting below .

    "Exception calling "Publish" with "1" argument(s): "The operation failed on one or more Metadata web service application proxies: Metadata Service Application"

    Any help on the above issue would be higly appriciated.

  4. I also faced the samie issue, open the powershell with runas administrator.

  5. Great example, thank you.

  6. You are a hero - thanx

  7. I was just about to write this. You saved me a lot of time. Thanks loads.

    I like the check to see if it has been published before too.

  8. Also had the "Exception calling "Publish" with "1" argument(s): "The operation failed on one or more Metadata web service application proxies: Metadata Service Application" Error.

    And RunAs Administrator did not solve it.

    Any ideas anyone...

    1. For those of you getting the error:
      "Exception calling "Publish" with "1" argument(s): "The operation failed on one or more Metadata web service application proxies: Metadata Service Application"

      And the ULS report errors for powershell.exe such as:
      Metadata web service application proxy Managed Metadata Service Proxy is not in a working state. Skip it.

      I had this error - and solved it by running the script on a server where "Managed Metadata Web Service" was started
      CA -> System -> Manage services on server (if this is not visible, launch IE as admin)

  9. Just what I needed as well, only I had a very "funny" (frustrating) issue. The published content types would get published to the subscribing site, only without their names.. Have to manually go in and press publish through the UI.

  10. I wrote a similar function to yours: I get my content types by filtering on the group names . One thing I found is for each new Content type you need to do an initial publish say with the UI . Otherwise you get your else clause.-

  11. Thanks For Your valuable posting, it was very informative. Am working in Erp Software Company In India

  12. I am happy to see this post.Thank you for sharing the great information.ERP in chennai

  13. 2016 was filled with more Air Jordan 12 releases than we could handle, and there’s actually still a couple Jordan 11 more dropping before the end of the year. What we didn’t see was any low-top versions of the Air Jordan 12 hit retailers.If you happen to be a fan Jordan Shoes 2016 of the 12 Low then the good news for you is that Jordan Brand plans on releasing a few different colorways in 2017 with one of them being previewed Jordan 7 Tinker Alternate for the first time up above. This Air Jordan 12 Low features a vibrant red suede all throughout the upper with black accents placed on the inner liner, laces, Jordan 13 Shoes mudguard, upper eyelets, heel tab, branding, and the back of the midsole. A red outsole wraps up the look.No exact release date is known yet for the Air Jordan Jordan Shoes 12 Low Red Suede but it is expected to release some time in 2017. Make sure you stay tuned to Kicks On Fire for updates.
    A woolen version of Jordans for sale the Air Jordan 11 is expected to be offered this year as part of JB’s standout Holiday 2016 lineup, which will join alongside the return of the iconic Air Cheap Jordans Jordan 11 Space Jam.As suggested, the basketball sneaker will host a wool constructed upper, which will essentially be similar to the upcoming AJ 3 Wool and AJ 12 Wool Kobe Bryant Shoes renditions as well. Dark grey and black comprises the model’s upper, while a white midsole unit and translucent outsole finishes off the more functional and premium profile.
    It Jordan 13 doesn’t get much more official than this. If you had any doubts that the Air Jordan 11 Space Jam would be returning this year then you can put those Jordan Eclipse doubts to rest as Nike has now given us our first official look at the highly anticipated release.Part of Nike’s “12 Soles” Collection that will be dropping in December, Kyrie Shoes the Air Jordan 11 Space Jam will come with an OG look as it features a higher patent leather cut in comparison to the last couple of releases.

  14. [url=][b]adidas yeezy boost 350[/b][/url]
    [url=][b]coach outlet online[/b][/url]
    [url=][b]moncler jackets[/b][/url]
    [url=][b]stan smith adidas[/b][/url]
    [url=][b]adidas uk[/b][/url]
    [url=][b]toms outlet[/b][/url]
    [url=][b]pandora charms sale clearance[/b][/url]
    [url=][b]michael kors outlet clearance[/b][/url]
    [url=][b]coach outlet store online[/b][/url]

  15. There are a lot of alternatives that can be used when it comes to writing quality content for our website and by not just using an article writing software.spin rewriter review

  16. Nice article, I loved it. Thanks for sharing and keep sharing.

  17. Your website content nice nice and interesting to observe.
    jobbörse Neunkirchen

  18. Is there a way to re-publish individual content types or perhaps a content type group?

  19. It is great to have visited your website. Thanks for sharing useful information. And also visit my website about health. God willing it will be useful too

    Pengobatan Scabies secara Alami
    Obat Penghilang Jerawat dan Bekasnya
    Cara Menyembuhkan Batuk Berkepanjangan

  20. Hey, Wow Provided Post will be Very much Informative to the People Who Visit this Site. Good Work! Thank You for Sharing.
    Education erp software in chennai

  21. También puede visitar una tienda de ladrillo y mortero de Michael Kors o su sitio web y comprar directamente un bolso Michael Kors desde allí. Usar un bolso de Michael Kors les permite a los demás reconocer que el habitante urbano educado toma la moda realmente con seriedad. Los bolsos de hombro son particularmente refinados y elegantes.

    {Bolsas Michael Kors Precios | Bolsos Michael Kors Outlet | Michael Kors Rebajas}

    En vacker konstnärlig skapelse av vävt läder, som ger ett skalskaligt utseende - liknar en snakeskin eller fiskhud, linjer utsidan av påsen. Läderens bältros är små läderringar. Det finns också gyllene accenter på väskan. Slutresultatet är svagt liknar kedjepost.

    {Michael Kors Rea | Michael Kors Väska Rea | Michael Kors Plånbok}