Skip to content

Instantly share code, notes, and snippets.

@aflyen
Created August 12, 2017 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflyen/b62e5663df5e42d59dd75c93866700ee to your computer and use it in GitHub Desktop.
Save aflyen/b62e5663df5e42d59dd75c93866700ee to your computer and use it in GitHub Desktop.
# Configuration
$SiteUrl = "https://TENANTID.sharepoint.com"
$TermGroupName = "Contoso"
$TermSetName = "Document Types"
$TermName = "Reports"
$TermLcid = 1033
$TermGuid = "2bdb40fd-02e4-4604-914e-9f8012685be0"
# Get correct termset
Connect-PnPOnline -Url $SiteUrl -Credentials $GlobalCredentialsId
$Context = Get-PnPContext
$TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context)
$TermStores = $TaxonomySession.TermStores
$Context.Load($TaxonomySession)
$Context.Load($TermStores)
Execute-PnPQuery
$TermStore = $TermStores[0]
$Context.Load($TermStore)
Execute-PnPQuery
$Group = $TermStore.Groups.GetByName($TermGroupName)
$TermSet = $Group.TermSets.GetByName($TermSetName)
$Context.Load($Group)
$Context.Load($TermSet)
Execute-PnPQuery
# Create new term
$Term = $TermSet.CreateTerm($TermName, $TermLcid, [System.Guid]::Parse($TermGuid))
$Context.Load($Term)
Execute-PnPQuery
Disconnect-PnPOnline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment