2

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

2

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()
  • 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

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.