logo
search
SharePoint Document Issues

How to Bulk Import Document Sets in SharePoint Using PowerShell

Steven ParkerSteven Parker Oct 13, 2026 869 views

Question details

The user needs to create Document Sets in bulk from an Excel file, apply corresponding metadata, and upload files from subfolders into SharePoint Online.

How to Bulk Import Document Sets in SharePoint Using PowerShell
Product
SharePoint Online
Device & OS
not provided
Scenario
Migrating or bulk-uploading structured document folders and metadata from local storage or Excel data into a SharePoint document library.
Observed behavior
SharePoint Online lacks a standard, out-of-the-box user interface to handle complex bulk imports of Document Sets alongside metadata and subfolder files simultaneously.
Before you start

Ensure you have SharePoint administrator permissions, the latest PnP PowerShell module installed on your machine, and a clean CSV file prepared with your metadata. Always test your scripts on a small sample dataset in a test environment before running a full bulk import.

Solution 1Recommended

Use PnP PowerShell to Bulk Create Document Sets and Apply Metadata

Since SharePoint Online does not provide a native bulk-import UI, using PnP PowerShell is the most effective method to automate reading data from a spreadsheet, creating Document Sets, and uploading files.

This process requires SharePoint customization and PowerShell scripting. By converting your Excel tracking sheet into a CSV file, you can use PnP PowerShell to iterate through each row, provision the Document Sets programmatically, and assign the correct metadata.

Because scripts interact directly with your SharePoint environment's structure, ensure your CSV columns precisely match the internal column names of your SharePoint library.

1
Prepare Your Data Source

Open your Excel file containing the Document Set names, required metadata, and local file paths. Save this file as a Comma Separated Values (.csv) file.

2
Connect to SharePoint Online

Open your PowerShell console as an Administrator. Type 'Connect-PnPOnline -Url <YourSiteUrl> -Interactive' and log in with your SharePoint admin credentials.

3
Import the CSV and Iterate

Use the 'Import-Csv' cmdlet to load your data. Create a 'foreach' loop to iterate through each row of the imported CSV data.

4
Create Document Sets and Update Metadata

Inside the loop, use 'Add-PnPFolder' or specific REST API calls wrapped in PowerShell to create the Document Set. Follow up with 'Set-PnPListItem' to apply the corresponding metadata fields from the current CSV row to the new Document Set.

5
Upload Subfolder Files

Add 'Add-PnPFile' commands within your loop to map the local file paths from your CSV and upload the respective files directly into the newly created Document Sets.

Use PnP PowerShell to Bulk Create Document Sets and Apply Metadata
Seek Scripting Guidance: If you encounter errors or need syntax help with your custom script, post your specific code in the Microsoft Q&A community under the 'SharePoint Development' and 'SharePoint' tags.
Free Microsoft Office alternative

Manage Your Import Data Effortlessly with WPS Office

While preparing complex data structures like Excel tables for SharePoint bulk imports, you need a reliable spreadsheet tool. WPS Office provides a lightweight, highly compatible alternative to Microsoft Office, perfect for organizing your Document Set metadata before exporting it to CSV for PowerShell.

  1. 1. Download and Install: Download WPS Office for free and install it on your computer to access the Spreadsheet application.
  2. 2. Open Your Import Data: Open your source Excel document containing the SharePoint metadata and folder structures in WPS Spreadsheet.
  3. 3. Format and Export to CSV: Ensure all column headers match your SharePoint internal names, then go to Menu > Save As, and select 'CSV (Comma delimited)' for your PowerShell script to read.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv) for seamless PowerShell data preparation.Lightweight and fast, making it ideal for managing large datasets and cleaning up metadata without lag.Free to use with a familiar, easy-to-navigate tabbed interface.Includes advanced data formatting and cleanup tools to prevent scripting errors.
microsoft office alternative - wps office

Frequently Asked Questions

Why can't I bulk import Document Sets directly from the SharePoint Online interface?

SharePoint Online does not provide a native bulk import feature for Document Sets that simultaneously applies metadata and uploads subfolder files. It requires custom development or PowerShell scripting to automate these specific, multi-step actions.

What is PnP PowerShell?

PnP (Patterns and Practices) PowerShell is a cross-platform command-line module providing over 600 commands. It allows administrators and developers to perform complex provisioning, artifact management, and bulk operations in SharePoint Online much easier than standard API calls.

How do I test my PowerShell script safely before a bulk import?

Always test your script by pointing it to a dedicated test SharePoint site or a separate document library. Use a small sample of your CSV data (e.g., 2 to 3 rows) to verify that the Document Sets are created properly and metadata is applied correctly before executing it on your entire dataset.