Skip to content

Instantly share code, notes, and snippets.

@nlarkin
Created August 27, 2013 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlarkin/6357491 to your computer and use it in GitHub Desktop.
Save nlarkin/6357491 to your computer and use it in GitHub Desktop.
Powershell function for Sharepoint 2010 to get a taxonomy term using a spsite object, a field name and label. In this scenario we pass back the label / value pair however you can easily modify to return the term object.
Function GetTaxonomyTerm($spsite, $field, $label)
{
Write-Host "Getting term for $($label)..."
$taxonomySession = Get-SPTaxonomySession -Site $spsite
$taxonomyField = $spsite.RootWeb.Fields.GetField($field)
$termStoreID = $taxonomyField.SspId
$termStore = $taxonomySession.TermStores[$termStoreID]
$termsetID = $taxonomyField.TermSetId
$termset = $termStore.GetTermSet($termsetID)
$term = $termset.GetTerms( $label, $true)
return [string] $term[0].Name +"|"+$term[0].Id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment