Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When using managed metadata, how can I find out, if a term is used (and if possible, how often it is used), without iterating all sites and lists/libraries on the sites?

share|improve this question
    
This is fantastic, but how would you find out what the code would be if you wanted it to also mark what the term set or group it is in? –  Carolynn Oct 9 at 20:53

1 Answer 1

up vote 1 down vote accepted

So, this is my own approach, it is iterating the site collections, but not their contents. It just checks the TaxonomyHiddenList for the terms it contains.

But if someone has a better idea, I would happily accept it :)

$usedTerms = @{}
Get-SPSite -Limit All | foreach {
    $web = $_.OpenWeb()
    $list = $web.Lists | where { $_.Title -eq "TaxonomyHiddenList" }
    $list.Items | foreach {
        if ($_ -ne $null)
        {
            $key = ($_["Path"] + " (" + $_["IdForTerm"] + ")")
            if ($usedTerms.ContainsKey($key))
            {
                $usedTerms[$key] = ($usedTerms[$key] + ", " + $web.Url)
            }
            else
            {
                $usedTerms.Add($key, $web.Url)
            }
        }
    }
}

$usedTerms
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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