SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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) 
      if($termSetNames -ccontains $_.Name)
        Write-Host $_.Name "will be deleted"

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

RemoveTermSet @store $termGroupName
share|improve this answer
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
@RobertLindgren True, but I needed a quick fix not to destroy the whole term group :) – Benny Skogberg Nov 7 '13 at 18:36

Your Answer


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.