Tuesday, 29 June 2010

Create a new Managed Metadata term with synonym in SharePoint 2010 using PowerShell

Use this script if you want to create a new term in the SharePoint 2010 Managed Metadata service with PowerShell. Incidentally, the Managed Metadata CSV import format provided out-of-the-box in SharePoint 2010 does not support synonyms, so you could easily use this code along with the Import-Csv PowerShell cmdlet to come up with a replacement format if you needed to support synonyms (will get around to posting a script at some point):

#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()

#Dispose of taxonomy site object
$taxonomySite.Dispose()

22 comments:

  1. I run this and i get an error saying "Cannot index into a null array". Any idea?

    ReplyDelete
  2. Very informative post. I sometimes do presentations on SharePoint and was wondering if I could use your Print List example in my presentations and refer my audience to your website for further info.

    ReplyDelete
  3. We prefer to honor several other net sites around the internet, even when they arent linked to us, by linking to them. Below are some webpages worth checking out.

    ReplyDelete
  4. These exercises will permit you to create much more lean muscle throughout your complete body,
    so you lose fat in all your difficulty zones. Boneka Wisuda

    ReplyDelete
  5. Excellent article. I will be experiencing some of these issues as well..

    ReplyDelete
  6. Your whole body system should remain in a silent and tranquil environment in order to help you correctly loosen up as you
    massage your foot.

    ReplyDelete
  7. I have had a difficult time clearing my mind in getting
    my thoughts out there. I truly do enjoy writing however it just
    seems like the first 10 to 15 minutes are generally
    lost just trying to figure out how to begin. Any ideas or tips?

    Many thanks!

    ReplyDelete