Managing SharePoint Term Store efficiently is crucial for maintaining metadata consistency across sites. PnP PowerShell simplifies the automation of Term Store operations, enabling users to create, update, delete, and export terms effortlessly.
This guide provides a step-by-step approach to automate SharePoint Term Store Management using PnP PowerShell.
Prerequisites
Before executing the script, ensure:
PnP PowerShell Installed
Install it using:
Install-Module -Name PnP.PowerShell -Force -AllowClobber
Admin Permissions in SharePoint Online
- You must be a SharePoint Term Store Administrator.
Connection to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
Step 1: Retrieve Term Store Information
To check existing Term Groups, Term Sets, and Terms, use:
# Get all Term Groups
Get-PnPTermGroup
# Get Term Sets under a specific Term Group
Get-PnPTermSet -TermGroup "Company Announcements Tags"
# Get Terms inside a Term Set
Get-PnPTerm -TermSet "Categories" -TermGroup "Company Announcements Tags"
🔹 This helps validate existing metadata structure before making changes.
Step 2: Create a New Term Group
A Term Group organizes related Term Sets.
New-PnPTermGroup -Name "HR Taxonomy" -Description "HR-related metadata"
Creates a new Term Group named HR Taxonomy.
Step 3: Create a Term Set
A Term Set contains structured metadata terms.
New-PnPTermSet -Name "Job Roles" -TermGroup "HR Taxonomy" -Lcid 1033
Creates a Job Roles Term Set inside HR Taxonomy.
LCID 1033 represents English (US).
Step 4: Add Terms to a Term Set
Now, populate the Job Roles Term Set with terms.
New-PnPTerm -TermSet "Job Roles" -TermGroup "HR Taxonomy" -Name "Software Engineer" -Lcid 1033
New-PnPTerm -TermSet "Job Roles" -TermGroup "HR Taxonomy" -Name "Data Analyst" -Lcid 1033
New-PnPTerm -TermSet "Job Roles" -TermGroup "HR Taxonomy" -Name "Cybersecurity Specialist" -Lcid 1033
Adds three job roles under Job Roles Term Set.
Step 5: Update an Existing Term
To rename or update a term:
Set-PnPTerm -Identity "Cybersecurity Specialist" -TermSet "Job Roles" -TermGroup "HR Taxonomy" -NewName "SOC Analyst"
Renames Cybersecurity Specialist to SOC Analyst.
Step 6: Delete a Term, Term Set, or Term Group
To delete a Term:
Remove-PnPTerm -Identity "Data Analyst" -TermSet "Job Roles" -TermGroup "HR Taxonomy" -Confirm:$false
To delete an entire Term Set:
Remove-PnPTermSet -Identity "Job Roles" -TermGroup "HR Taxonomy" -Confirm:$false
To delete a Term Group:
Remove-PnPTermGroup -Identity "HR Taxonomy" -Confirm:$false
Warning: Deleting a Term Group removes all associated Term Sets and Terms.
Step 7: Export Term Store to CSV
To export all terms for backup:
$terms = Get-PnPTermGroup | ForEach-Object {
Get-PnPTermSet -TermGroup $_.Name | ForEach-Object {
Get-PnPTerm -TermSet $_.Name -TermGroup $_.Group
}
}
$terms | Select Group, TermSet, Name | Export-Csv -Path "C:\SharePoint_Terms.csv" -NoTypeInformation
Creates a CSV backup of all Term Groups, Term Sets, and Terms.
Step 8: Import Terms from CSV (Bulk Creation)
Prepare a CSV file with the format:
TermGroup | TermSet | TermName |
---|---|---|
HR Taxonomy | Job Roles | Frontend Developer |
HR Taxonomy | Job Roles | Backend Developer |
HR Taxonomy | Job Roles | Cloud Engineer |
Run the following script to import terms from CSV:
$csvData = Import-Csv -Path "C:\SharePoint_Terms.csv"
foreach ($row in $csvData) {
New-PnPTerm -TermSet $row.TermSet -TermGroup $row.TermGroup -Name $row.TermName -Lcid 1033
}
Creates multiple terms in bulk from the CSV file.
Step 9: Schedule the Script for Automation
1️⃣ Open Task Scheduler
2️⃣ Click Create Basic Task
3️⃣ Set Trigger: Daily/Weekly
4️⃣ Set Action: Start a Program
5️⃣ In Program/script, enter:
-ExecutionPolicy Bypass -File "C:\YourScriptPath\ManageTermStore.ps1"
6️⃣ Click Finish
Now, Term Store operations run automatically on schedule.
Troubleshooting Common Issues
Issue 1: PnP PowerShell Not Recognized
Run:
Update-Module -Name PnP.PowerShell
Issue 2: Connection Errors
Ensure you are connecting with Admin Privileges:
Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
Issue 3: Terms Not Updating
- Verify that the Term Group and Term Set names match.
- Check if the Term Set is not locked in SharePoint.