Delete Term Group using PowerShell

Below is a script that I used to delete a term group and all the term sets within that group.


$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}

if ($snapin -eq $null)
{
  Write-Host "`nLoading SharePoint Powershell Snapin`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

function DeleteTermGroup {
$centralAdmin = Read-Host "Central Admin Url:"
$termstoreName = "Term Store Name"
$groupName = Read-Host "Group name"

$site = Get-SPSite $centralAdmin
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termstore = $session.TermStores[$termstoreName]
$group=$termStore.Groups[$groupName]
$group.TermSets|foreach{
$_.Delete()
$termstore.CommitAll()
}

    $group.Delete()

$termstore.CommitAll()

Write-Output "Deleted $groupName"
}


DeleteTermGroup

$input = Read-Host "Enter any key to exit"

Exit

Comments

Popular posts from this blog

SharePoint 2013 - Working with Display Template for Content Search Web Part

How to Customize MOSS Site Manager (Site Content and Structure Page)

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365