Have a problem when trying to iterate through termstore in Managed Metadata service application.
Termstore architecture is shown below:
MMS
Termgroup
Terset
Level 1 Term
Level 2 Term
Level 3 Term
Level 1 Term
Level 2 Term
Level 3 Term
etc
I'm using the following powershell script:
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termStore = $session.TermStores[0]
$group = $termStore.Groups["%Termgroup name%"]
$termSet = $group.TermSets["%Termset name%"]
When i use the following command:
$terms = $termSet.Terms
$term = $terms | ?{$_.Name -eq "%Level 3 Term%"}
$term is null because $terms array contains only Level 1 Terms (including all child terms).
If i try following:
$terms = $termSet.GetAllTerms
$terms variable contains all terms (should according to method overview) but i still unable to make a selection of specified term.
So the question is - how can i iterate through all terms in termset and select one (or many, depends on need) term?
Thanks!