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
                $spCTPublish.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 $CTHubURL "is not a content type hub site"
    }
    #Dispose of site and web objects
    $ctHubWeb.Dispose()
    $ctHubSite.Dispose()
}

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:

image

72 comments:

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

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

    ReplyDelete
  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.

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

    ReplyDelete
  5. Great example, thank you.

    ReplyDelete
  6. You are a hero - thanx

    ReplyDelete
  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.

    http://www.sharepointshowboat.com

    ReplyDelete
  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...

    ReplyDelete
    Replies
    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)

      Delete
  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.

    ReplyDelete
  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.-

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

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

    ReplyDelete
  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.

    ReplyDelete
  14. [url=http://www.yeezyboost-350.us.com][b]adidas yeezy boost 350[/b][/url]
    [url=http://www.coachfactory-outletonlines.us.com][b]coach outlet online[/b][/url]
    [url=http://www.moncler-outlet.us.com][b]moncler jackets[/b][/url]
    [url=http://www.adadasstansmith.com][b]stan smith adidas[/b][/url]
    [url=http://www.adidastrainersuk.org.uk][b]adidas uk[/b][/url]
    [url=http://www.tomsshoesoutlet.in.net][b]toms outlet[/b][/url]
    [url=http://www.pandoracharmssaleclearance.me.uk][b]pandora charms sale clearance[/b][/url]
    [url=http://www.michaelkorsoutletclearance.com.co][b]michael kors outlet clearance[/b][/url]
    [url=http://www.coachoutletstore-online.us.com][b]coach outlet store online[/b][/url]
    [url=http://www.abercrombieandfitch.in.net][b]bercrombie[/b][/url]
    0323shizhong

    ReplyDelete
  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

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

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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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}

    ReplyDelete
  22. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi | Coimbatore taxi

    ReplyDelete
  23. Are you blacklisted? Struggling to get a personal loan? Has your application been DECLINED due to Low Credit Score? Over COMMITTED? Affordability? But you know you can afford this loan. Loans Approved in 4hours, you can email us at opploansLLC@gmail.com

    Names:
    Occupation:
    Loan Amount Needed:
    Loan Duration:
    Your Country:
    Mobile NO:
    Purpose Of Loan:
    Email Address:
    monthly income:
    Sex:
    Age:

    Opportunity Financial, LLC

    ReplyDelete
  24. Information from this blog is very useful for me, am very happy to read this blog Kindly visit us @ Luxury Watch Box | Shoe Box Manufacturer |  Candle Packaging Boxes | Wallet Box

    ReplyDelete
  25. A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
    There are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
    Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
    Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
    Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
    Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
    Coach Store Near Me trends come and go, but a Coach stands the test of time.
    The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
    Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
    All Michael Kors Outlet Online Store have serial numbers.

    ReplyDelete
  26. No matter what type of Michael Kors Bags Outlet each individual got, they all had one thing in common. We all know that getting something on sale is like winning a mini lottery, but to find a name brand handbag like Michael Kors Black Friday Sale for instance, discounted is like a slice of heaven on earth. I have personally attacked my husband with hugs and kisses when finding Official Coach Outlet Online at discounted prices.

    Michael Kors Factory Outlet stores can be found in malls all over. MK Outlet and other Coach merchandise can also be found in some boutiques. Inspired by the same material baseball gloves are made from, these Coach Bags On Sale Online are versatile and stylish. Since it's conception, the Michael Kors Handbags Outlet has been produced into a variety of designs, colors, shapes, and styles that have won top pick of millions of women the world over.

    New Michael Kors Bags are the most sought after handbag. Since Coach Outlet Online is one of the most recognized name brands in the world of fashion, you will find A-list celebrities down to small girls wearing them.

    tags:Coach Outlet|Coach Bags Factory Outlet|Coach Purses Outlet

    ReplyDelete