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

Exporting SharePoint Online Document Metadata using PnP PowerShell

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

Loading

Metadata in SharePoint Online provides essential details about documents, such as title, author, created date, modified date, version, and custom columns. Exporting this metadata can be useful for auditing, compliance, and reporting.

This guide covers how to export document metadata from SharePoint Online using PnP PowerShell, including:

✔ Connecting to SharePoint Online
✔ Exporting metadata from a document library
✔ Filtering metadata based on conditions
✔ Saving metadata to CSV for reporting


Step 1: Install and Connect to SharePoint Online

Ensure you have PnP PowerShell installed:

Install-Module -Name PnP.PowerShell -Force -AllowClobber

Update the module if needed:

Update-Module -Name PnP.PowerShell

Now, connect to SharePoint Online:

Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/YourSite" -Interactive

Step 2: Export Document Metadata from a Library

To export all document metadata from a specific document library, run:

# Define variables
$libraryName = "Documents" # Change this to your document library name
$exportFile = "C:\Backups\DocumentMetadata.csv"

# Get all items in the library
$items = Get-PnPListItem -List $libraryName -Fields "FileLeafRef", "FileRef", "Author", "Editor", "Created", "Modified"

# Create an array to store metadata
$metadataList = @()

foreach ($item in $items) {
$metadataList += [PSCustomObject]@{
"File Name" = $item["FileLeafRef"]
"File URL" = $item["FileRef"]
"Created By" = $item["Author"].Email
"Modified By" = $item["Editor"].Email
"Created Date" = $item["Created"]
"Modified Date" = $item["Modified"]
}
}

# Export to CSV
$metadataList | Export-Csv -Path $exportFile -NoTypeInformation
Write-Host "Metadata exported to $exportFile"

✔ Saves file name, URL, author, editor, and timestamps to a CSV file.


Step 3: Export Custom Metadata Fields

If your document library has custom columns (e.g., Category, Department), include them:

$customFields = "Category", "Department"  # Change to match your metadata fields

$items = Get-PnPListItem -List $libraryName -Fields "FileLeafRef", "FileRef", "Author", "Editor", "Created", "Modified", $customFields

$metadataList = @()

foreach ($item in $items) {
$metadataList += [PSCustomObject]@{
"File Name" = $item["FileLeafRef"]
"File URL" = $item["FileRef"]
"Created By" = $item["Author"].Email
"Modified By" = $item["Editor"].Email
"Created Date" = $item["Created"]
"Modified Date" = $item["Modified"]
"Category" = $item["Category"]
"Department" = $item["Department"]
}
}

$metadataList | Export-Csv -Path $exportFile -NoTypeInformation
Write-Host "Metadata including custom fields exported to $exportFile"

✔ Captures custom metadata fields along with standard ones.


Step 4: Filter Metadata Based on Conditions

To export metadata only for files modified in the last 30 days:

$days = 30
$cutoffDate = (Get-Date).AddDays(-$days)

$filteredItems = $items | Where-Object { $_["Modified"] -gt $cutoffDate }

$filteredItems | Export-Csv -Path "C:\Backups\RecentFiles.csv" -NoTypeInformation
Write-Host "Exported only files modified in the last $days days."

✔ Helps track recently updated files.


Step 5: Automate Metadata Export with Task Scheduler

To schedule daily metadata exports:

  1. Save the script as ExportMetadata.ps1.
  2. Open Task Scheduler → Create Basic Task.
  3. Set Trigger → Daily at 1:00 AM.
  4. Set Action → Start a Program.
  5. Use this PowerShell command: -ExecutionPolicy Bypass -File "C:\Scripts\ExportMetadata.ps1"

✔ Ensures automated daily exports without manual effort.

Posted Under PNP PowerShellAutomation Compliance CSV Export Document library File Properties Metadata Export PNP PowerShell Reporting SharePoint Auditing SharePoint online

Post navigation

Java Password Hashing Strategies
Java Microservices with Spring Cloud

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