SharePoint 2013 – PowerShell – Taxonomy through Client Object Model

I tried to get to the my Taxonomy session through the client object model. Well if you Bing (I actually used google. But I’m Microsoft focussed so I thought I better mention Bing here) and go to the Microsoft pages documentation the there isn’t much available. All I found is some empty pages.

So first of all load the dlls ( Make sure that you’ve got these dlls on your client!)

Add-Type -Path “c:\Scripts\Microsoft.SharePoint.Client.dll”
Add-Type -Path “c:\Scripts\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “c:\Scripts\Microsoft.SharePoint.Client.Taxonomy.dll”

The first two are for the SharePoint Client Object Model. The 3rd dll is for the taxonomy stuff.

Then I setup the Client Object Model Context

$ctx = new-object Microsoft.SharePoint.Client.ClientContext($siteUrl)

Then like without the Client Object Model I need to get the session.

$session = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx);

Ok, so now I’ve got a taxonomy session

Now I need to get to my TermStores

$termstores = $session.TermStores

I’m likely only to have one termstore, but just in case.

$termstores |% {
$termstore = $_;
if ($termstore.Name -eq “Managed Metadata Service”)
… More to come here …

Then to complete the above code I got my groups and groupset from the termstore

$groups = $termstore.Groups;

$groupset = $groups.GetByName(“My Company”);

$termsets = $groupset.TermSets;

$industrytermSet = $termsets.GetByName(“Industry”);

And my termset is available.

So now we’re nearly there.

I want to be able to get to my terms in a termset. So just a few more steps to go.

Now I’m getting all my terms ( I’ve only got 22 in this termset so no problem to pick them all up)

$industryterms = $industrytermSet.GetAllTerms()

Now to get my term all I need to do is:

$term = $industryterms.GetByName(“Aerospace”)

Hopefully this will help someone else.

3 thoughts on “SharePoint 2013 – PowerShell – Taxonomy through Client Object Model

  1. Hello! Came across this while trying to figure out why mine isn’t working. I’m trying to do the same but getting a conversion error. Using SDK v16.0.4002.1211.

    Cannot convert argument context with value Microsoft.SharePoint.Client.ClientContext for GetTaxonomySession to type Microsoft.SharePoint.Client.ClientRuntimeContext: Cannot convert the Microsoft.SharePoint.Client.ClientContext value of type Microsoft.SharePoint.Client.ClientContext to type Microsoft.SharePoint.Client.ClientRuntimeContext

  2. Hi Patrick,
    I have seen that error before. Most of the time this is down to dll versions not being right. Can you check if you have multiple versions of the Microsoft.SharePoint.Client dlls on your system? Did you reboot after the SDK installation?

    1. Hi Pieter. Thanks for the reply. Indeed I think it was multiple SDKs installed that was causing the error. Seems odd that Add-Type doesn’t load the right version, despite being explicitly typed. I resolved by using the older LoadWithPartialName way:


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: