I have a requirement where I need to find the Taxonomy Field assigned to a page property.

For Example, Language is a page property and Unity is the group name assigned to it and Language is the termset for that property.

Now, I need to find that dynamically to know what group is assigned to the page property using PowerShell.

I have cast it into a taxonomy field and got 2 properties like SspId and TermSetId. By using the SspId, I was able to find the termstore properly, but not the group and the termset.

My Code :

$TaxFldLanguage = $pagesList.Fields.GetByInternalNameOrTitle("Language");

#casting here
$objTxFieldOffice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($ctx, $TaxFldOffice);

$termStoreID = $objTxFieldOffice.SspId.ToString();
$termSetID = $objTxFieldOffice.TermSetId.ToString();

#find the termstore and the matching termsetID
$termStores = $TaxonomySession.TermStores.GetById($termStoreID);

if ($termStores) {
    $termStore = $termStores[0];
    $Groups = $termStore.Groups;

    foreach ($grp in $Groups) {
        #loop through all termsets in all groups and check with the $termSetID
        $grpTermsets = $grp.TermSets;

        foreach ($trmset in $grpTermsets) {
            Write-Host "Termset: " + $trmset.Name -ForegroundColor Gray;
            $terms = $trmset.Terms;

            foreach ($trm in $terms) {
                Write-Host $trm.Id -ForegroundColor Blue;
                if ($trm.Id -eq $termSetID) {
                    Write-Host "Group: "+ $grp.Name + "Termset:"+ $trmset.Name -ForegroundColor DarkRed;

1 Answer 1


This is how I got the termstore and termset assigned to the page property.

#load TermStore here
$TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($ctx);
$TermStore = $TaxonomySession.GetDefaultSiteCollectionTermStore();

#get page property
$TaxFldLanguageB = $pagesList.Fields.GetByInternalNameOrTitle("LanguageB");

#cast to taxonomy
$objTxFieldOffice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($ctx, $TaxFldLanguageB);

#get termstore and termset id
$termStoreID = $objTxFieldOffice.SspId.ToString();
$termSetID = $objTxFieldOffice.TermSetId.ToString();

$termsetData = $TermStore.GetTermSet($termSetID);

$termsData = $termsetData.Terms;

foreach ($objTerm in $termsData) {
    Write-Host $objTerm.Name " - " $objTerm.Id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.