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 "https://domainName.sharepoint.com/sites/siteName"
$termSet = New-PnPTermSet -Name "Category" -TermGroup "Categories"
$term = New-PnPTerm -Name "Category1" -TermSet "Category" -TermGroup "Categories"
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
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 = "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
Answered by GSD - SharePoint on January 19, 2021
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.
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP