In a PowerShell script, I'd like to retrieve the url of the content type hub tied to a site collection.

My scripts muse use the CSOM.

I tried :

$Context = New-Object Microsoft.SharePoint.Client.ClientContext("http://myserver/mysite")
$MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context)

$termStore = $MMS.GetDefaultSiteCollectionTermStore()



This code does not throw any error, but does not output anything.

The server side equivalent code does output the hub url:

$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)

How to retrieve this url is CSOM ?

I suspect I should specify the ContentTypePublishingHub property in the Load method, but I didn't found the syntax to specify additional properties to load. None of this worked :

$Context.Load($termStore, "ContentTypePublishingHub")
$Context.Load($termStore, $termStore.ContentTypePublishingHub)
$Context.Load($termStore, {param($ts) $ts.ContentTypePublishingHub })
$Context.Load($termStore, @({param($ts) $ts.ContentTypePublishingHub }))

[Edit] I tried the same code using C#:

var Context = new ClientContext("http://myserver/mysite");
var MMS = TaxonomySession.GetTaxonomySession(Context);

var termStore = MMS.GetDefaultSiteCollectionTermStore();


This code throws a PropertyOrFieldNotInitializedException. If change the load method to :

 Context.Load(termStore, ts=>ts.ContentTypePublishingHub);

The code outputs the expected urls.

This is an evidence for me, that the PS code does not specify property to load properly.

  • I know this sounds really basic but have you made sure the $MMS object is actually being instantiated properly by checking it's other objects and properties? – Thomas Gass Jun 19 '17 at 10:12
  • Again this might seem like a basic thing to point out but in SOM you're using $session.DefaultSiteCollectionTermStore.ContentTypePublishingHub.OriginalString to get the URL, but in CSOM you're only using $termStore.ContentTypePublishingHub, so maybe you just need to add the OriginalString property onto the end of the CSOM command? – Thomas Gass Jun 19 '17 at 10:17
  • @ThomasGass: ContentTypePublishingHub property is present (but empty) in the $termstore object, and is a string. – Steve B Jun 19 '17 at 15:19
  • That doesn't seem right - surely ContentTypePublishingHub should be an object, with OriginalString holding the string value? Or is OriginalString a generic method/property (I've not seen it before or had to use the CTH in a script). – Thomas Gass Jun 19 '17 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.