1

I have searched the interwebs forever but can't seem to find a simple example of how to get a taxonomy term by guid in Powershell using the CSOM. Can anyone help me please?

2 Answers 2

1

Sample demo by CSOM PowerShell.

$url="http://sp"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"

$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)

$MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($clientcontext)
$clientContext.Load($MMS)
$clientContext.ExecuteQuery()

$guid = New-Object System.Guid("28cd5378-92f3-48bc-aa39-5e27ea475211");
$term=$MMS.GetTerm($guid)
$clientContext.Load($term)
$clientContext.ExecuteQuery()
Write-Host $term.Name
2

We do have method on TermSet object to getTerm based on GUID.

TermSet.GetTerm(Guid) Method - Gets a Term from the current TermSet based on its ID.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.taxonomy.termset.getterm

Below code snippet from ref link -https://seyedketabchi.wordpress.com/2011/03/27/accessing-taxonomies-from-powershell/

$url = "http://MySP2010/sites/CoolSites/"
$web = Get-SPWeb $url
$taxonomySession = Get-SPTaxonomySession -Site $web.Site
$termStore = $taxonomySession.TermStores["Managed Metadata Service"];
foreach($item in $termStore.Groups){
if($item.Name -eq "Marketing")
{
$group = $item
}
}
Write-Host "---->: " $group.Name

$termset = $group.TermSets["Marketing Initiative"];
$guid = New-Object System.Guid("c1353ee2-b2b2-4fc9-90a2-3b912390b6ac");
$term = $termset.GetTerm($guid);


Write-Host $term.Name;

}

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.