I have been creating a load of site columns with powershell from a .csv file. I am now trying to create new taxonomy or metadata field:

               $spField = $web.Fields.CreateNewField($fieldType, $siteColumn.DisplayName)
                    # updat properties related ot MMS
                    # Update the properties of the new field.
                    $spField.SspId = $termSet.TermStore.ID
                    $spField.TermSetId = $termSet.Id 
                    $spField.AnchorId = $termID

but I also want to set a default value (not just the anchor for a range of terms)

  $defaultTerm = $terms | Where-Object {$_.Name -eq $siteColumn.Default}

Now I am stuck because I need update $spField.DefaultValue with a format it accepts e.g.

 45;#Customer Document|60d5d501-3d38-4842-80f0-c897a12b7e34

How can I do this from a .csv file?

2 Answers 2


For each field you should identify the default term name. Then to get the Unique ID, you need to iterate through the term store as below

$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) 
$termStore = $session.TermStores[0] 
$group = $termStore.Groups["GroupName"] 
$termSet = $group.TermSets["TermsetName"] 
$terms = $termSet.GetAllTerms() 
$term = $terms | ?{$_.Name –eq "TermName"}

Once you have the $term, you can form the default value as

"45;#" + $term.Name + "|" + $term.Id
  • 2
    Please use -1instead of 45though, since we do not know the lookup id Nov 4, 2014 at 11:35
  • Thanks for the reply. Ok, I see you have located the (default) term and you have formatted a string with its properties. But how did you get the "nn;#" part.. I know that is the internal format it is just not easier to see how it is stored Nov 4, 2014 at 11:54
  • The lookup id (called WssId "officially") is a sitecollection-specific value. You can read more about that and find C# code samples how to get / create that in these posts: pholpar.wordpress.com/2010/02/03/… pholpar.wordpress.com/2010/12/23/…
    – pholpar
    Nov 4, 2014 at 12:06
  • I understand. I little inconsistent of sharepoint ( not using a guid) but I see that as I am creating my site column in a Site collection it makes sense. Ok will test this out in the office tomorrow thanks also @Amal Nov 4, 2014 at 19:56

The "45" in @Amal's example is the SpssId. The SpssId only gets created when a taxonomy term has been used in a list or a library. It is actually the Id of a list item for a given term in the TaxonomyHiddenList.

Rather that use "45" or "-1" you can simply write a once off script to create a list item for every term in the term store. The Taxonomy Update Scheduler timer job will then create items in the TaxonomyHiddenList for each term, the Id of each of these list items is the SpssId accessible in the API TaxonomyField.GetWssIdsOfTerm object/method. This method will fail if the term has never been used before so that is why you need the once of script and a list to populate items with every term thereby using all the terms.

Such is the SP design for this, you cannot get an Spssid for a given term unless it has actually been used in a list or a library and only after the Taxonomy Update Scheduler has created the list items in the TaxonomyHiddenList. I think its an odd design but there may reasons why it works this way...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.