Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
$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

share|improve this question
1  
possible duplicate of powershell script add a managed metadata column –  PirateEric Jan 27 '12 at 19:25
    
Agree, and see my answer –  Colin Feb 26 '12 at 21:20
    
Thanks Guys .....This helepd me a lot –  user7551 Mar 27 '12 at 10:13

1 Answer 1

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

share|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 '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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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