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?

  • 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? – user34167 Oct 9 '14 at 20:53

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)
                $usedTerms.Add($key, $web.Url)

  • 1
    The taxonomyhiddenlist can also contain items which were previously used, but not in use any more. So be aware that this approach might get you false positives. Another approach might be to leverage the search engine, you can use the TaxCatchAll field to search for term usage. – Jasper Aug 26 '15 at 5:50
  • @Jasper, good point, thanks for the warning. If you elaborate your approach in an answer I try and accept it as answer. – Hinek Oct 6 '15 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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