Created
August 27, 2013 18:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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