Creating site collection termgroup by pnp powershell

SharePoint Asked by extractor on January 19, 2021

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 ""
$termSet = New-PnPTermSet -Name "Category" -TermGroup "Categories"
$term = New-PnPTerm -Name "Category1" -TermSet "Category" -TermGroup "Categories"

4 Answers

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

Answered by Koen Zomers on January 19, 2021

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

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Taxonomy.dll"

#Variables for Processing
$AdminURL = ""
$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
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()

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

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

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


SharePoint Online: Create New Group in Term Store using PowerShell

Answered by GSD - SharePoint on January 19, 2021

Thanks Rene. I just come across the . 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.

Answered by extractor on January 19, 2021

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.

Answered by Rune Sperre on January 19, 2021

Add your own answers!

Related Questions

Replace Source query string value without redirecting

1  Asked on November 28, 2021 by leonidasfett


Workflow on Survey list not starting?

2  Asked on November 25, 2021 by dylan-cristy


Sharepoint Foundation 2013: single cpu

1  Asked on November 25, 2021 by woef


Double click on ribbon save button

1  Asked on November 23, 2021 by jonata-ornelli


Imported Excel Spreadsheet not Filtering Column

1  Asked on November 23, 2021 by bhav


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP