Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
    }
}
share|improve this question
add comment

1 Answer

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"
share|improve this answer
    
You can remove the CommitAll in the inner foreach –  Colin Mar 9 '12 at 1:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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