$webURL = "http://xxx/sites/wingtipcalculator"
$spSite = New-Object Microsoft.SharePoint.SPSite($webURL)
$spWeb = $spSite.OpenWeb()

$listTemplate = $spWeb.ListTemplates["Custom List"];

$spweb.Lists.Add("List4","Data information DTU",$listTemplate)

write-host "List added in the Web : " $spweb -foregroundcolor Yellow

$spList = $spWeb.Lists["List4"]
$spList.Fields.Add("Publication Date","DateTime",1)
$taxonomySite = Get-SPSite http://XXX:2010
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores["Managed Metadata Service"]
write-host "Connection made with term store -"$termStore.Name
$taxonomySession = $spWeb.site;

$termStoreGroup = $termStore.Groups["XX"];
$termSet = $termStoreGroup.TermSets["General Business Taxonomy (v1.0)"];
$TaxonomyField = $spList.Fields.Add("TaxonomyFieldType", "Test1"); 
$taxonomyField.SspId = $termStore.Id;
    $taxonomyField.TermSetId = $termSet.Id;

trying to use the above script but unable to cretae the required metadata column in list


You should get the taxonomy session of the site in which you are adding field.

$taxonomySite = Get-SPSite http://XXX:2010 
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite 

Also try calling Update() method after you set the SSPId and TermSetID

  • Hi asish patel i tried doing that im getting the field but its not pointing to the term store its giving termstore is null..please help me out.. – vikram06 Jan 27 '12 at 20:28
  • what is taxonomySession.TermStores.Count? – Ashish Patel Jan 27 '12 at 20:36
  • Thank You very much Asish Patel I have resolved with it...:-) – vikram06 Jan 30 '12 at 15:05
  • 1
    Please accept this as the answer, if it solved the problem, rather than leave a comment. – SPDoctor Mar 27 '12 at 14:33
  • If it did not solve the problem, please post what you did to correct it as an answer. If Ashish's answer did help but was not complete, consider accepting his answer but adding the additional steps as a comment. The helps the community by increasing the value of your question. – Robert Kaucher Aug 17 '13 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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