1

Deleting managed metadata term stores using powershell script. Was trying with the below script but getting error "Cannot index into null array". Please help out thanks in advance....

Add-PSSnapin Microsoft.SharePoint.Powershell
Clear-Host
$taxonomySite = get-SPSite "http://"
$mmsServiceName = "Managed Metadata Service"
#$taxonomySite = Get-SPSite $centralAdminURL
$taxSession = Get-SPTaxonomySession -Site $taxonomySite
$termStore = $taxSession.TermStores[$config.configuration.configSettings.mmsServiceName]
$grpName = "XXX"
$grpManager = ""
$termSetName = ""
$termSetOwner = ""
$tsStakeHolder = ""
Clear-Host 
$group = $termStore.Groups["XXX"]
if ($contentsource -ne $null)
{
    $contentsource.Delete()
}

if ($termStore -ne $null)
{

    if ($group -ne $null)
    {
        $group.TermSets|foreach{
            $_.Delete()
            $termStore.CommitAll()
        }
        $group.Delete()
        $termStore.CommitAll()
    }
}

2 Answers 2

1

After spending sometime found the solution just need to mention the terms

#Script for deleting managed metadata 
#Calling Taxonomy site and group Name
Add-PSSnapin Microsoft.SharePoint.Powershell
Clear-Host 
$taxonomySite = get-SPSite "http:" 
$mmsServiceName = "Managed Metadata Service"
$grpName = "XXX"
$grpManager = "YYY"
$termSetName = "XXXX"
$termSetOwner = ""
$tsStakeHolder = ""
$centralAdmin = "XXXXXX"
#$termsetName = "VVV"
#$grpName = "XXXX"

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

        Write-Output "Deleted $groupName"
1
  • You can remove the CommitAll in the inner foreach
    – Colin
    Mar 9, 2012 at 1:18
-1

$site = Get-SPSite $centralAdmin is not necessary, just use $taxonomySite in TaxonmySession ... also last line should be Write-Output "Deleted $grpName" not $groupName ....

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.