Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top