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

I want to remove a Termset that contains several terms. How do I accomplish this?

share|improve this question
add comment

1 Answer

You need to have the initial variables at hand as well as the Term Store Name (in the @store variable), to make this work.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

# Initial Variables
$SiteCollectionUrl = "http://portal/"
$termGroupName = "Intranet"
$termSetNames = @("TermSet1", "TermSet2")

function RemoveTermSet([Microsoft.SharePoint.Taxonomy.TermStore]$store, [string]$groupName) 
{
  if ($group -ne $null) 
  {
    $group.TermSets|foreach{
      if($termSetNames -ccontains $_.Name)
      {
        Write-Host $_.Name "will be deleted"
        $_.Delete()
        $store.CommitAll()
      }
    }
  }
}

$session = Get-SPTaxonomySession -Site $SiteCollectionUrl
$store = $session.TermStores["Managed Metadata Service"]
$group = $session.TermStores.Groups | Where-Object {$_.Name -eq $termGroupName}

RemoveTermSet @store $termGroupName
$store.CommitAll()
share|improve this answer
1  
Working script, but is it not a bit weird to be dependent on a variable declared in an outer scope in RemoveTermset function? :) –  Robert Lindgren Nov 7 '13 at 17:56
1  
@RobertLindgren True, but I needed a quick fix not to destroy the whole term group :) –  Benny Skogberg Nov 7 '13 at 18:36
add comment

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.