- ####
- # www.letssharepoint.com
- ####
- # Get Taxonomy Session and Term Store
- $site = Get-SPSite http://yoursiteurl
- $taxonomySession = Get-SPTaxonomySession -site $site
- $termStore = $taxonomySession.TermStores["Your Managed Metadata Service Application"]
- # Create Groups
- $termStoreGroup = $termStore.CreateGroup("Your Groupname")
- $termStoreGroup.Description = "Your Description"
- $termStoreGroup.AddGroupManager("domain\user")
- $termStoreGroup.AddContributor("domain\user")
- # Create Termset
- $termSet = $termStoreGroup.CreateTermSet("Your Termset name")
- # Create Term
- $term = $termSet.CreateTerm("Your Term Name", LanguageID)
- $termStore.CommitAll()
- ####
- # www.letssharepoint.com
- ####
- # Load Microsoft.SharePoint.Taxonomy to work with TaxonomyFieldValueCollection
- [Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy")
- # Get Taxonomy Session and Term Store
- $site = Get-SPSite http://yoursiteurl
- $taxonomySession = Get-SPTaxonomySession -site $site
- $termStore = $taxonomySession.TermStores["Your Managed Metadata Service Application"]
- # Get Web, List item and Taxonomy Field
- $web = Get-SPWeb http://yourweburl
- $list = $web.Lists["YourList"]
- $item = $list.GetItemById(1)
- $taxField = $item.Fields["YourTaxField"]
- # Create Taxonomy Field Collection for a Multi Managed Metadata Field
- $taxCollection = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValueCollection $taxField
- ## Get Terms and Add them to the TaxonomyFieldValueCollection
- # Get Term Group
- $termStoreGroup = $termStore.Groups["My Group"]
- # Get Term Set
- $termSet = $termStoreGroup.TermSets["My Termset"]
- # Get Terms
- $term1 = $termSet.Terms["Term1"]
- $term2 = $termSet.Terms["Term2"]
- $term3 = $termSet.Terms["Term3"]
- # Get TaxonomyFieldValues
- $taxValue1 = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue($taxField)
- $taxValue1.TermGuid = $term1.Id
- $taxValue1.Label = $term1.Name
- $taxValue1.WssId = -1
- $taxValue1 = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue($taxField)
- $taxValue2.TermGuid = $term2.Id
- $taxValue2.Label = $term2.Name
- $taxValue2.WssId = 0
- $taxValue3 = new-object Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue($taxField)
- $taxValue3.TermGuid = $term3.Id
- $taxValue3.Label = $term3.Name
- $taxValue3.WssId = 1
- # Add Values to Tyxonomy Field Value Collection
- $taxCollection.Add($taxValue1)
- $taxCollection.Add($taxValue2)
- $taxCollection.Add($taxValue3)
- # Update Managed Metadata Colum on Item
- $taxField = SetFieldValue($item, $taxCollection)
- $item.Update()
Good Luck,
Andreas
Zwei kleine Optimierungen:
AntwortenLöschenZeile 36 muss lauten: $taxValue2
Und in Zeile 50 muss der Befehl lauten: $taxField.SetFieldValue($item, $taxCollection)
Ansonsten ein tolles Skript.