1

how could i create terms inside existing group/termset

$TaxonomySession = Get-SPTaxonomySession -site $TaxonomySite $termStore=$TaxonomySession.TermStores["Managed MetaDataService"] $group=$termStore.Groups["Users"] $termSet=$group.TermSets["Name"] foreach($termSet in $Content.Settings.Terms.Term) { CreateTerm($termSet) } $termStore.CommitAll() 

I get this error

Cannot index into a null Array groups["Users"] termsets["Department] CreateTerm: The term CreateTerm is not recognized as the name of a cmdlet

3 Answers 3

0

You can create term to a particular term set using

$termGroup = $termStore.Groups["GroupName"] $termSet = $termGroup.TermSets["TermSetName"] $term = $termSet.CreateTerm("new term name") $termStore.CommitAll() 
0

Please refer the below PowerShell function using Client Object to create a new term in a Term Set. This can can be executed from remote machine you need not to be on server.

You need to set few parameters and pass it to function.

Parameter explanation:

$MMSbaseurl - Its the URL to website on which you have termsets and groups for e.g. http://yoursite

$credentials - Your credentials to the site, you need to have enough permissions to access and edit meta data

$GroupName - Name of the group in Term Set lives

$TermSetName - Name of the term set in which you want to create a new term

$lcid - locale ID you are using

 function Create-NewTerm() { [CmdletBinding()] param( [Parameter(Mandatory=$true)][string]$MMSbaseurl, [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials, [Parameter(Mandatory=$true)][string]$GroupName, [Parameter(Mandatory=$true)][string]$TermSetName, [Parameter(Mandatory=$false)][int]$lcid ) begin{ Write-Host "Preparing for term store...." -ForegroundColor Cyan try{ $Context = New-Object Microsoft.SharePoint.Client.ClientContext($MMSbaseurl) } catch { Write-Host "Error:-->> Unable to create ClientContext at " $MMSbaseurl -ForegroundColor Red } try { Write-Host "Binding to Term store through managed metadata services for ($MMSbaseurl) " -ForegroundColor Cyan $Context.Credentials = $credentials $MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context) $Context.Load($MMS) $Context.ExecuteQuery() Write-Host "Retrieving Term Stores" -ForegroundColor Cyan $TermStores = $MMS.TermStores $Context.Load($TermStores) $Context.ExecuteQuery() Write-Host "Binding term store" -ForegroundColor Cyan $TermStore = $TermStores[0] $Context.Load($TermStore) $Context.ExecuteQuery() Write-Host "Binding term store Groups" -ForegroundColor Cyan $Groups = $TermStore.Groups $Context.Load($Groups) $Context.ExecuteQuery() foreach($Group in $Groups) { if ((($Group.Name.ToLower()) -eq $GroupName.ToLower())) { $SelectedGroup = $Group Write-Host "Group found." -ForegroundColor Cyan break } } $Context.Load($SelectedGroup) $Context.ExecuteQuery() Write-Host "Bind to term set" -ForegroundColor Cyan $TermSets = $SelectedGroup.TermSets $Context.Load($TermSets) $Context.ExecuteQuery() foreach($TermSet in $TermSets) { if ((($TermSet.Name.ToLower()) -eq $TermSetName.ToLower())) { $SelectedTermSet = $TermSet Write-Host "Term set found." -ForegroundColor Cyan break } } $Context.Load($TermSet) $Context.ExecuteQuery() #Term creation # $NewTerm = $TermSet.CreateTerm("New Term", $lcid, [System.Guid]::NewGuid().toString()) $Context.Load($NewTerm) $Context.ExecuteQuery() Write-Host "New term created successfully" -ForegroundColor Cyan } catch{ Write-Host "Error -->>>> " $_.Exception.Message -ForegroundColor Red } } end{ $Context.Dispose() } } #Get and Set credentials $credentials = Get-Credential #Call Function # Create-NewTerm "http:YourSite.com" $credentials "New Group" "New Term Set" 1033 

Same function you can refer at this blog

0

try this code,

#Connect to Central Admin $taxonomySite = get-SPSite http://centraladminsite:port #Connect to Term Store in the Managed Metadata Service Application $taxonomySession = Get-SPTaxonomySession -site $taxonomySite $termStore = $taxonomySession.TermStores["Managed Metadata Service"] write-host "Connection made with term store -"$termStore.Name #Connect to the Group and Term Set $termStoreGroup = $termStore.Groups["Group Name"] $termSet = $termStoreGroup.TermSets["Term Set Name"] #Create term, term description, and a synonym $term = $termSet.CreateTerm("Test Term", 1033) $term.SetDescription("This is a test", 1033) $term.CreateLabel("This is a test synonym", 1033, $false) #Update the Term Store $termStore.CommitAll() 

Source: Create a new term in Existing Group and Term Set Under Managed Metadata Service Application with PowerShell

1
  • You cannot call a method on a null-valued expression on "Test Term" and "This is test" and "This is a test synonym" Commented May 4, 2015 at 5:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.