Quantcast
Viewing all articles
Browse latest Browse all 41

SharePoint Add Terms to Termstore via Powershell

And another cool thing you can do with Powershell: Create Terms and Termgroups with Powershell. I just post about a simple way, but you can use it to build a function or a script which imports a csv or txt file.


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Connect to the Metadata Service with central admin url
$taxSite = get-SPSite "http://server:port/"
$taxonomySession = Get-SPTaxonomySession -site $taxSite
$termStore = $taxonomySession.TermStores["Managed Metadata Service"]

#Check if Group already exists
if($termStore.Groups["MyGroup"] -eq $null)
{
$termStoreGroup = $termStore.CreateGroup("MyGroup")
$termStoreGroup.Description = "My Termstore für Anything"
$termStoreGroup.AddGroupManager("domain\user")
$termStoreGroup.AddContributor("domain\user")
}
else
{
$termStoreGroup = $termStore.Groups["MyGroup"]
write-host "Group exists already"
}
if($termStoreGroup.TermSets["MyTermSet"] -eq $null)
{
$termSet = $termStoreGroup.CreateTermSet("MyTermSet")

}
else
{
$termSet = $termStoreGroup.TermSets["MyTermSet"]
write-host "TermSet exists already"
}

#Create the Terms out of this list
$termsList = "Value1;Value2;Value3;Value4"
$termsArray = $termsList.Split(";")

foreach($termAdd in $termsArray)
{
#Create Term
if($termSet.Terms[$termAdd] -eq $null)
{
$term = $termSet.CreateTerm($termAdd, 1033)
#$term.SetDescription(“This is a test”, 1033)
#$term.CreateLabel(“This is a test synonym”, 1033, $false)

write-host "Term $termAdd was added"
}
else
{
write-host "Term $termAdd was already added"
}
}
#Update the Term Store
$termStore.CommitAll()


The $termslist could also be the csv or txt-file which imports the terms. Just see this as a basic script.

Hope it helps, cause it is really cool.


Viewing all articles
Browse latest Browse all 41

Trending Articles