How to Bulk Import Document Sets in SharePoint Using PowerShell
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.

- 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.
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.
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.
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.
Open your PowerShell console as an Administrator. Type 'Connect-PnPOnline -Url <YourSiteUrl> -Interactive' and log in with your SharePoint admin credentials.
Use the 'Import-Csv' cmdlet to load your data. Create a 'foreach' loop to iterate through each row of the imported CSV data.
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.
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.

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. Download and Install: Download WPS Office for free and install it on your computer to access the Spreadsheet application.
- 2. Open Your Import Data: Open your source Excel document containing the SharePoint metadata and folder structures in WPS Spreadsheet.
- 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.

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.




