Thursday, 26 July 2012

Creating new terms in a taxonomy store using PowerShell

Ever wondered how to create new terms in a taxonomy set using PowerShell? It's super easy.

Get the Taxonomy Session for your site
$ts = Get-SPTaxonomySession -Site http://myweb/
$tstore = $ts.TermStores[0]

List the term groups (if you don't know the name)
$tstore.Groups | ft name

Get the term group
$tgroup = $tstore.Groups["AdministrativeTermsets"]

List the term sets if you don' t know the name
$tgroup.TermSets | FT Name

Get the termset
$eTypeTS = $tgroup.TermSets["EventType"]

Create a new term (the CreateTerm method can be call with just two parameters, the name and locale id, if you're happy for SharePoint to automatically generate a Guid for the terms ID).
$eTypeTS.CreateTerm("Seminar", 1033, [System.Guid]("9A4B69D1-D359-4152-B9F6-34357C769711"))

When you're finished creating terms, update the termgroup to commit the changes.
$tgroup.TermStore.CommitAll()

1 comment: