1

I am trying to create site collection term store in my SP online site collection. by mistake i deleted the default site collection termstore. When i try to create new site collection term store using below commands, i got access denied error. Is it possible to create site collection termstore like this?

Connect-PnPOnline -Url "https://domainName.sharepoint.com/sites/siteName"
$termSet = New-PnPTermSet -Name "Category" -TermGroup "Categories"
$term = New-PnPTerm -Name "Category1" -TermSet "Category" -TermGroup "Categories"
1

It is now possible to use PnP PowerShell to retrieve, create and delete the site collection scoped taxonomy term group. I have added it through this PR.

Sample usage:

Install-Module PnP.PowerShell -AllowPrerelease
Connect-PnPOnline -Url https://tenant.sharepoint.com -PnPManagementShell
Add-PnPSiteCollectionTermStore
Get-PnPSiteCollectionTermStore
Remove-PnPSiteCollectionTermStore
0

Thanks Rene. I just come across the https://github.com/pnp/PnP-PowerShell/issues/1968 . It looks like the site collection term tore once deleted can not be created again. You can delete and create terms but not the Term store. I end up creating a new site. it is good lesson. Never delete the default site collection term store.

0

You can use the below CSOM PowerShell script to create new the term group:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"

#Variables for Processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$TermGroup ="Regions"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
    $Ctx.Credentials = $Credentials

    #Get the term store
    $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()

    #Check if the given group exists already
    $TermGroups = $TermStore.Groups
    $Ctx.Load($TermGroups)
    $Ctx.ExecuteQuery()
    $Group = $TermGroups | Where-Object {$_.Name -eq $TermGroup}

    If(-not $Group)
    {
        #Create Term Group
        $NewGroup = $TermStore.CreateGroup($TermGroup, [System.Guid]::NewGuid().toString())
        $Ctx.Load($NewGroup)
        $Ctx.ExecuteQuery()

        Write-host "Term Group '$TermGroup' Created Successfully!" -ForegroundColor Green
    }
    else
    {
        Write-host "Term Group '$TermGroup' Exists Already!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Adding Term Group!" $_.Exception.Message
}

Source:

SharePoint Online: Create New Group in Term Store using PowerShell

2
  • bibur, this may create term group under default site collection term group. but can you confirm if there is a script to create site collection termgroup when the default one is deleted – extractor Apr 29 '20 at 15:35
  • I will check and update here... meanwhile if you have test tenant environment can you run this script and see. Otherwise you can raise a ticket to Microsoft, they will guide you how to restore your default term group which was deleted, they might restore the term store database for tenant if needed. – GSD - SharePoint Apr 29 '20 at 18:20
-1

There aren't any PowerShell commands to create a site collection term group directly, you will first have to create it using the GUI.

There is a script here that seems to do the same, if you would prefer to script it.

After you have created the term group, you can add new term sets to it using the code in your example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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