Managed metadata in SharePoint 2010 is a brand new feature allowing you to manage metadata from a centrally defined repository.
For example, you may want to use terms in drop down selections on the forms of your site driven by this centrally managed collection of options.
If you have a site accessible in multiple language locales too – you can also define managed metadata for those multiple locales and pull the right term for the right language as your users interact with the site.
When you move the site from development, to staging, to production, as a part of your solution deployment – you probably want all the moving pieces inlcuding managed metadata terms to be moved with it.
In this post I would like to show you how you can provision managed metadata terms using PowerShell.
I assume you have a development environment where managed metadata service is already configured.
Open SharePoint 2010 Management Shell and execute the script below:
$SiteUrl = "http://www.contoso.com"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
Write-Host "Connecting to the term store and creating a new group"
$TaxonomySession=Get-SPTaxonomySession -Site $SiteUrl
$TermStore=$TaxonomySession.TermStores["Managed Metadata Service"]
$Group=$TermStore.CreateGroup("Branch 1")
$TermStore.CommitAll()
Write-Host "Creating a term set"
$TermSet=$Group.CreateTermSet("Branch Group 1")
$TermStore.CommitAll()
Write-Host "Creating a term"
$MarketingTerm=$TermSet.CreateTerm("Term 1",1033)
$HRTerm=$TermSet.CreateTerm("Term 2",1033)
$DeliveryTerm=$TermSet.CreateTerm("Term 3",1033)
$TermStore.CommitAll()
Above, the Get-SPTaxonomySession gets a hold of the taxonomy service application. Then we connect to the root element in the taxonomy tree Managed Metadata Service. Our terms will have to live under a term group, which in our case is called Branch 1. Each term group must have a term set, which basically contains a set of terms, in our case called Branch Group 1. Finally, we create terms within our term set.
In here, we define the term itself and language locale for the language (1033 is engligh US).