$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

link|improve this question

0% accept rate
1  
possible duplicate of powershell script add a managed metadata column – PirateEric Jan 27 at 19:25
Agree, and see my answer – Colin Feb 26 at 21:20
Thanks Guys .....This helepd me a lot – madhu Kashyap Mar 27 at 10:13
feedback

1 Answer

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

link|improve this answer
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 at 20:28
what is taxonomySession.TermStores.Count? – Ashish Patel Jan 27 at 20:36
Thank You very much Asish Patel I have resolved with it...:-) – vikram06 Jan 30 at 15:05
Please accept this as the answer, if it solved the problem, rather than leave a comment. – SPDoctor Mar 27 at 14:33
feedback

Your Answer

 
or
required, but never shown

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