Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

Automating SharePoint Metadata Management using PnP PowerShell

Posted on March 19, 2025March 19, 2025 by Rishan Solutions

Loading

Metadata in SharePoint is crucial for organizing, categorizing, and retrieving content efficiently. PnP PowerShell provides a robust way to automate metadata management, including creating term sets, adding terms, managing site columns, and updating metadata values across documents and lists.

This guide will walk you through automating SharePoint Metadata Management step by step using PnP PowerShell.


Prerequisites

Before you begin, ensure you have the following:

  1. PnP PowerShell Installed
    If not installed, run: Install-Module -Name PnP.PowerShell -Force -AllowClobber
  2. Connect to SharePoint Online Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive
    • Replace yourtenant with your actual SharePoint tenant name.
    • The -Interactive parameter allows for MFA authentication.

Step 1: Retrieve Existing Metadata (Term Store, Site Columns, Content Types)

Get All Term Groups in the Term Store

Get-PnPTermGroup
  • Lists all term groups available in the Term Store.

Get Term Sets from a Specific Term Group

Get-PnPTermSet -Group "Enterprise Metadata"
  • Replace "Enterprise Metadata" with your actual term group name.

Get Terms from a Term Set

Get-PnPTerm -TermSet "Project Categories" -Group "Enterprise Metadata"
  • Replace "Project Categories" and "Enterprise Metadata" with actual values.

Get All Site Columns

Get-PnPField
  • Retrieves all site columns in SharePoint.

Step 2: Create and Manage SharePoint Metadata

Create a New Term Group

New-PnPTermGroup -Name "Project Metadata" -Description "Metadata for project categorization"

Create a Term Set within the Group

New-PnPTermSet -Name "Project Types" -Group "Project Metadata" -Lcid 1033
  • 1033 is the LCID (Language Code ID) for English.

Add Terms to a Term Set

New-PnPTerm -TermSet "Project Types" -Group "Project Metadata" -Name "Infrastructure" -Lcid 1033
New-PnPTerm -TermSet "Project Types" -Group "Project Metadata" -Name "Software Development" -Lcid 1033
New-PnPTerm -TermSet "Project Types" -Group "Project Metadata" -Name "Marketing Campaign" -Lcid 1033
  • This adds three terms under the “Project Types” term set.

Create a Managed Metadata Site Column

Add-PnPField -DisplayName "Project Category" -InternalName "ProjectCategory" -Group "Custom Columns" -Type TaxonomyFieldType
  • Managed Metadata Columns are stored as TaxonomyFieldType.

Associate the Site Column with a Term Set

First, retrieve the Term Set ID:

$termSet = Get-PnPTermSet -Group "Project Metadata" -Name "Project Types"
$termSet.Id

Then, associate it with the column:

Set-PnPTaxonomyField -Identity "ProjectCategory" -TermSetId $termSet.Id

Step 3: Apply Metadata to Lists and Libraries

Add a Managed Metadata Column to a SharePoint List

Add-PnPField -List "Documents" -DisplayName "Project Category" -InternalName "ProjectCategory" -Type TaxonomyFieldType

Set Metadata for a List Item

Set-PnPListItem -List "Documents" -Identity 1 -Values @{"Project Category"="Infrastructure"}
  • This assigns the “Infrastructure” metadata value to item ID 1 in the Documents library.

Bulk Update Metadata for Multiple Documents

$docs = Get-PnPListItem -List "Documents"
foreach ($doc in $docs) {
Set-PnPListItem -List "Documents" -Identity $doc.Id -Values @{"Project Category"="Software Development"}
}
  • This applies the “Software Development” category to all documents in the library.

Step 4: Automate Metadata Management with a PowerShell Script

Complete Script to Automate Metadata Management

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -Interactive

# Create a New Term Group
New-PnPTermGroup -Name "Project Metadata" -Description "Metadata for projects"

# Create a New Term Set
New-PnPTermSet -Name "Project Types" -Group "Project Metadata" -Lcid 1033

# Add Terms to the Term Set
$terms = @("Infrastructure", "Software Development", "Marketing Campaign")
foreach ($term in $terms) {
New-PnPTerm -TermSet "Project Types" -Group "Project Metadata" -Name $term -Lcid 1033
}

# Create a Managed Metadata Site Column
Add-PnPField -DisplayName "Project Category" -InternalName "ProjectCategory" -Group "Custom Columns" -Type TaxonomyFieldType

# Get Term Set ID and Associate with Site Column
$termSet = Get-PnPTermSet -Group "Project Metadata" -Name "Project Types"
Set-PnPTaxonomyField -Identity "ProjectCategory" -TermSetId $termSet.Id

# Add Managed Metadata Column to Documents Library
Add-PnPField -List "Documents" -DisplayName "Project Category" -InternalName "ProjectCategory" -Type TaxonomyFieldType

# Apply Metadata to All Documents
$docs = Get-PnPListItem -List "Documents"
foreach ($doc in $docs) {
Set-PnPListItem -List "Documents" -Identity $doc.Id -Values @{"Project Category"="Infrastructure"}
}

Write-Host "Metadata Management Automated Successfully!"

Step 5: Verify and Monitor Metadata Updates

After running the script:

  • Go to SharePoint Online → Documents Library
  • Check if the “Project Category” metadata column is created and populated correctly.
  • Navigate to Term Store Management in SharePoint Admin Center to confirm that terms are added.

Troubleshooting Common Issues

Issue 1: PnP PowerShell Commands Not Recognized

Run the following to update your module:

Update-Module -Name PnP.PowerShell

Issue 2: Term Set Not Found

Ensure the term set name and group match exactly:

Get-PnPTermSet -Group "Project Metadata"

Issue 3: Metadata Not Applied to Documents

Try re-running the metadata assignment script after verifying the field exists:

Get-PnPField -List "Documents"
Posted Under PNP PowerShellcloud solutions Content Management Document Management System Enterprise Content Management Information Management IT Automation Managed Metadata Metadata Management Metadata Strategy Metadata Tagging Microsoft 365 Microsoft 365 Compliance Microsoft 365 Security Microsoft SharePoint Office 365 PnP Management PNP PowerShell PowerShell scripting SharePoint SharePoint administration SharePoint Automation SharePoint Best Practices SharePoint Columns SharePoint Customization SharePoint Development SharePoint Document library SharePoint Governance SharePoint List Automation SharePoint Metadata SharePoint online SharePoint Online Best Practices Taxonomy in SharePoint TaxonomyFieldType Term Sets Term Store

Post navigation

IoT in Home Entertainment Systems
IoT for Home Health Monitoring

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions