Friday, 11 June 2010

Create a new term in Managed Metadata with PowerShell

Use this script if you want to create a new term in the SharePoint 2010 Managed Metadata Service with PowerShell:

#Connect to Central Admin
$taxonomySite = get-SPSite http://centraladminsite:port

#Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores["Managed Metadata Service"]
write-host "Connection made with term store -"$termStore.Name

#Connect to the Group and Term Set
$termStoreGroup = $termStore.Groups["Group Name"]
$termSet = $termStoreGroup.TermSets["Term Set Name"]

#Create term, term description, and a synonym
$term = $termSet.CreateTerm("Test Term", 1033)
$term.SetDescription("This is a test", 1033)
$term.CreateLabel("This is a test synonym", 1033, $false)

#Update the Term Store
$termStore.CommitAll()

13 comments:

  1. This powershell script works just fine, but I'm trying to perform this type of operation from a custom web service and the CommitAll() method sends unauthorized access exception, do you know how to grant the appropriate permissions to the user? (I am farm admin on local machine pre-development server) please send an e-mail if you have the answer, i'd appreciate it

    ReplyDelete
  2. Hi,

    This script is great.
    Whats the difference between metadata and new columns for document library?

    ReplyDelete
  3. I get an error..."Cannot Index into a null array"...any idea?

    ReplyDelete