<Caution>This post is based on the SharePoint 2013 Consumer Preview. Thus, behavior described here may change in the next release of the platform</Caution>
When a site collection is created and if the “SharePoint Server Publishing Infrastructure??? site collection feature is activated, SharePoint 2013 automatically creates a term group in the term store attached to the web application. This term group can then be used for the navigation. The structure below is therefore created :
But, when you delete the site collection, the term group and its structure underneath will remain, which can in one sense be understood. The drawback of this is that once the site collection is deleted, you can’t see it in the Term Store Management Tool from the Central Admin site. It also means that if you create a site collection with the same name as the previous one, this term group will be suffixed by a number, like “-1??? or “-2???. This can be a bit dirty.
Two possibilities to avoid this situation :
- Delete the Term Sets and Term Group from the site collection before its deletion
- Use PowerShell to delete these ghost Term Groups if it is too late.
For the second solution, the following script can be used :
$Site = get-SPSite “$url”
$ServiceName = “Managed Metadata Service”
$session = Get-SPTaxonomySession -Site $Site
$termStore = $session.TermStores[$ServiceName]
$termGroup = $termStore.Groups[$termGroupName]
“About to delete Term group in”
“URL : ” + $url
“Group : ” $termGroup
if ($termStore -ne $null)
{
if ($termGroup -ne $null)
{
$termGroup.TermSets | ForEach {
“deleting ” + $_.Name
$_.Delete()
$termStore.CommitAll()
$_.Name + “deleted”
}
$termGroup.Delete()
$termStore.CommitAll()
}
}
$Site represents the target site collection URL, and $termGroupName is the name of the Term Group you want to delete
If you want to check what are the existing Term Groups in your store, you can use this script :
$Site = get-SPSite “$url”
$ServiceName = “Managed Metadata Service”
$session = Get-SPTaxonomySession -Site $Site
$termStore = $session.TermStores[$ServiceName]
“Groups in”
“URL : ” + $url
if ($termStore -ne $null)
{
$termStore.Groups | ForEach {
$_.Name
}
}
0 Comments