Skip to main content

SharePoint PowerShell to Manage Term Store / Add Terms using PowerShell

SharePoint PowerShell to Manage Term Store / Add Terms


//get the term store
$mysite = get-spsite “http://yoursite:portnumber
$taxonomySession = get-taxonomySession -site $mysite
$termStore = $taxonomySession.TermStores[“Managed Metadata Service”]


//now we will create the Term Store groups. Before we create any group we will check if the group already exists
Example 1:


if($termstore.groups["News Keys"] -eq $null) { $termstoregroup = $termstore.creategroup("News Keys");  $termstore.description = "News Group";  $termstore.addgroupmanager ("KS\spadmin"); $termstore.addcontributor ("ks\k.singh");$termStore.CommitAll();}


This is not working as “description” is not an identified property.


Example 2:


if($termstore.groups["Main News Keys"] -eq $null) { echo "group is not there";  echo "group is there"; $termstoregroup = $termstore.creategroup("Main News Keys"); $termstore.commitall();   }

Example 3:
$session = Get-SPTaxonomySession -Site "http://ksshrpt01/";
$termStore = $session.TermStores[“Managed Metadata Service”];
$group = $termstore.CreateGroup(“News Group”);
$group.Description = "My News Group";
$termStore.addgroupmanager ("KS\spadmin");
$termStore.CommitAll();
$termSet = $group.CreateTermSet(“Sports”,1033);
$termSet.Description = “Sports”;
$termSet.IsAvailableForTagging = $true;
$termSet.IsOpenForTermCreation = $true;
$termStore.CommitAll();


I encountered many issues/errors and finally went through. I will advise the following troubleshooting tips.


  1. termstore.description("") - Invalid command. This never worked for me. I shall update this once I come across any solution to this. Remove this cmdlet if you too face the same issue.
  2. I faced issue related to Permission (UnAuthorized User). I started the PowerShell console as Administrator and still I had the same issue.
  3. Central Admin -> Manage Service applications -> Managed Metadata Service -> Select and go to permission. Assign permission to the user running PowerShell.
  4. Central Admin -> Service Applications->Managed Metadata Service -> Properties -> Set term store administrator as the user you want. Save it and reset IIS as a precautionary measure.


The Create TermStore Group command shall now work for you.



Both of the following commands worked well.


  1. PS> if($termstore.groups["Main News Keys"] -eq $null) { echo "group is not there";  $termstoregroup = $termstore.creategroup("Main News Keys");  $termstore.commitall();   }
  2. PS>$session = Get-SPTaxonomySession -Site "http://ksshrpt01/";
PS>$termStore = $session.TermStores[“Managed Metadata Service”];
PS>$group = $termstore.CreateGroup(“News Group”);
PS>$group.Description = "My News Group";
PS>$termStore.CommitAll();


*We will use the second command for all further examples

Please check the following screen.


Use following the command to assign permission to the group.


PS> $termstoregroup.addGroupManager("ks\spadmin")
PS> $termstoregroup.AddContributor("ks\k.singh")


You need to commit the changes to the Term Store.


PS>$termStore.CommitAll();


Let’s create Term Sets in the Term Store

PS> $newTermSet = $termstoregroup.CreateTermSet("Sports",1033)
PS> $newTermSet = $termstoregroup.CreateTermSet("Politics",1033)
PS C:\Users\spadmin> $newTermSet = $termstoregroup.CreateTermSet("Nation",1033)
PS C:\Users\spadmin> $newTermSet = $termstoregroup.CreateTermSet("Business",1033)
PS C:\Users\spadmin> $termstore.commitall()



Hope this helps…..

Comments

Popular posts from this blog

Visual Studio Build Issue : Build: 0 succeeded or up-to-date, 0 failed, 1 skipped

"Unable to build or clean the solution in Visual Studio (applicable to almost all versions), output window message is : Build: 0 succeeded or up-to-date, 0 failed, 1 skipped". If you are facing the above issue, you are at the right place. Perhaps following can help you. BTW, the above image is self explanatory, let me still brief if in case the image is not getting downloaded on your Internet connection. In VS menu, go to Tools -> Options. Select -> Projects and Solutions -> Build and Run. Uncheck - "Only build startup projects and dependencies on Run." Your problem shall be resolved. Thank you for visitng my blog.

SharePoint log error "Cannot find site lookup info for request Uri http://"

There are many reasons for which you can have this error in your SharePoint server logs. One of the scenerio is explained below. Main Reason: One of the major reason for this error is; the SharePoint is not able to resolve the URL. There is something wrong with the alternate access mapping. Please make sure the alternate access mapping is configured properly. For more details on alternate access mapping in SharePoint, please visit: Alternate Access Mapping We had sharepoint 2016 and all website under that were https:// from the firewall. When we tried to load the web site, error occured with a Correlation Id. After checking the code I found the error message "Cannot find site lookup info for request Uri http://". I URL was able to authenticate the user but on page load the error occurs. My alternate access mapping was: https://mysite                                   ...