Managing MMS could be more easier via PowerShell. Today I had to delete hundreds of terms from an MMS. First to check if terms are real, I created for a short script to list them.
function Get-SPManagedMetadataTerm{ [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( [parameter(Mandatory=$true,Position=0)]$SiteUrl, [parameter(Mandatory=$true,Position=1)]$GroupName, [parameter(Mandatory=$true,Position=2)]$TermSetName, [parameter(Position=3,ValueFromPipeline=$true)]$TermName ) Begin{ [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null $site = New-Object Microsoft.SharePoint.SPSite($SiteUrl) $taxonomySession = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) $Group = $taxonomySession.TermStores.Groups | ?{$_.Name -like $GroupName} $TermSet = $Group.TermSets | ?{$_.Name -like "$TermSetName"} } Process{ $Term = $TermSet.Terms | ?{$_.Name -like $TermName} if($Term) { $Term.Name } else { "($TermName) could not found!" } } }
There is a little modification in the script to deleting terms which found.
function Delete-SPManagedMetadataTerm{ [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact='High')] param( [parameter(Mandatory=$true,Position=0)]$SiteUrl, [parameter(Mandatory=$true,Position=1)]$GroupName, [parameter(Mandatory=$true,Position=2)]$TermSetName, [parameter(Position=3,ValueFromPipeline=$true)]$TermName ) Begin{ [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null $site = New-Object Microsoft.SharePoint.SPSite($SiteUrl) $taxonomySession = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) $Group = $taxonomySession.TermStores.Groups | ?{$_.Name -like $GroupName} $TermSet = $Group.TermSets | ?{$_.Name -like $TermSetName} } Process{ $Term = $TermSet.Terms | ?{$_.Name -like $TermName} if($Term) { if($PSCmdlet.ShouldProcess("Term (" + $($Term.Name) + ") will be deleted from ($($Term.TermStore.Name + "/" + $Group.Name + "/" + $TermSet.Name))")) { $Term.Delete() $Term.TermStore.CommitAll() "Term (" + $($TermName) + ") has been deleted from ($($Term.TermStore.Name + "/" + $Group.Name + "/" + $TermSet.Name))" } } else { "($TermName) could not found!" } } }
The end you could easily check and delete a bunch of terms like this.
$terms = Get-Content terms.txt $terms| Get-SPManagedMetadataTerm -SiteUrl https://<SiteUrl> -GroupName <GroupName> -TermSetName <TermSetName> $terms| Delete-SPManagedMetadataTerm -SiteUrl https://<SiteUrl> -GroupName <GroupName> -TermSetName <TermSetName> -Confirm:$false