How to Create Terms in SharePoint 2013 using PowerShell


Sathish Nadarajan
SharePoint MVP
Published On :   09 Feb 2015
Visit Count
Today :  5    Total :   10165
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


In this article, let us see, how to create Terms in SharePoint 2013 using PowerShell.

These scripts are very simple. But very much useful while Planning for a deployment. If we create using the User Interface, then the GUID cannot be defined by us. If we want to keep the same GUID across various environments, then we need to keep this approach.

The script is very straight forward and there is nothing much to discuss about this. We can download the executable version of this script on the bottom of this page, with the sample CSV File as well.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".\CreateTerms-$LogTime.rtf"
 
 
 cls
 
 
 ##================================================================================================
 ## Description	: This script is used to Set the TermSet for the Navigation and Set the Catalog, Item Page URLs.
 ## Author		: Sathish Nadarajan
  
 ##================================================================================================
 
 
  
 $Host.UI.RawUI.WindowTitle = "-- Set Term URLs --"
 
 $StartDate = Get-Date
 Write-Host -ForegroundColor White "------------------------------------"
 Write-Host -ForegroundColor White "| Update the Navigation Tag and Catalog, Item Page URLs |"
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 Write-Host -ForegroundColor White "------------------------------------"
 
 
 
 #start-transcript $logfile
 
 $ErrorActionPreference = "Stop"
 ######################### Add SharePoint PowerShell Snapin ###############################################
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) 
 {
     Add-PSSnapin Microsoft.SharePoint.Powershell
 }
 
 ########################### End of Add SharePoint PowerShell Snapin ##################################
 
 ######################## Set Execution Path ################################################
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
 “TermName `t” + “TermName `t”  + “TermName `t” + “TermName `t” + “TermName `t” + “TermName `t” + “TermName `t” + “TermName `t”>> TermGUID.csv
 
 function CreateTerms([string] $caURL,[string] $groupName,[string] $termsetName,[string] $TermName, [string] $TermGuid)
 {
 
     $caSite = Get-SPSite -Identity $caURL
 
     $taxonomySession = Get-SPTaxonomySession -Site $caSite
  
     $termStore = $taxonomySession.DefaultKeywordsTermStore
  
     $termStoreGroup = $termStore.Groups[$groupName]
  
     $termset = $termStoreGroup.TermSets[$termsetName]
  
      
 
     
     $termset.CreateTerm($TermName,1033,$TermGuid)
      
     $termStore.CommitAll()
      
 }
  
 
 
 $CreateTermsCSV = $scriptBase + "\" + "CreateTerms.csv"
 
 import-csv $CreateTermsCSV | where {
     #UpdateTerms $_.CentralAdminUrl $_.TermGroupName $_.TermSetName $_.TermGUID $_.ChangeCatalogTargetURL $_.ChangeCatalogTargetUrlForChildTerms $_.ChangeTargetURL $_.ChangeTargetUrlForChildTerms $_.CatalogTargetUrl $_.CatalogTargetUrlForChildTerms $_.TargetUrl $_.TargetUrlForChildTerms
 
     CreateTerms $_.CentralAdminUrl $_.TermGroupName $_.TermSetName $_.TermName $_.TermGUID
     											
 
 
     
 }
 

Download HERE

Happy Coding.

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

Migratiin Tools for SharePoint