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
$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