2
$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)
$spList.Fields.Add("Headline","Text",1)
$spList.Fields.Add("LeadParagraph","Text",1)
$spList.Fields.Add("FullText","Text",1)
$spList.Fields.Add("ContactName","Text",1)
$spList.Fields.Add("ModifiedTest","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;
$spWeb.Dispose()

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

2

1 Answer 1

2

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

5
  • 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.. Commented Jan 27, 2012 at 20:28
  • what is taxonomySession.TermStores.Count? Commented Jan 27, 2012 at 20:36
  • Thank You very much Asish Patel I have resolved with it...:-) Commented Jan 30, 2012 at 15:05
  • 1
    Please accept this as the answer, if it solved the problem, rather than leave a comment. Commented Mar 27, 2012 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. Commented Aug 17, 2013 at 15:11

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.