2

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

1 Answer 1

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()
2
  • 1
    Working script, but is it not a bit weird to be dependent on a variable declared in an outer scope in RemoveTermset function? :) Commented Nov 7, 2013 at 17:56
  • 1
    @RobertLindgren True, but I needed a quick fix not to destroy the whole term group :) Commented Nov 7, 2013 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.