Forum Discussion
Beth_Culpepper
Oct 25, 2023Brass Contributor
Bulk create folders in document library
I have a document library with a folder that represents every state in the United States. Within each folder, I need to create a folder for each one of our theaters. Within each theater folder need...
LeonPavesic
Oct 26, 2023Silver Contributor
Hi Beth_Culpepper,
you can try to do this by using PowerShell:
- Prepare an Excel file with the following columns:
- State
- Theater
- AdditionalFolder
- Subfolder1
- Subfolder2
- Save the Excel file to your local computer.
- Open a PowerShell console and connect to your SharePoint site.
- Run the following PowerShell script:
# Import the CSV file
$CSVFile = Import-Csv "C:\Path\To\CSVFile.csv"
# Get the document library
$Library = Get-PnPList -Identity "DocumentLibraryName"
# Create each folder in the document library
ForEach($Row in $CSVFile) {
$FolderURL = $Library.RootFolder.ServerRelativeUrl + "/" + $Row.State + "/" + $Row.Theater + "/" + $Row.AdditionalFolder + "/" + $Row.Subfolder1 + "/" + $Row.Subfolder2
Resolve-PnPFolder -SiteRelativePath $FolderURL | Out-Null
}
- Replace C:\Path\To\CSVFile.csv with the path to your CSV file.
- Replace DocumentLibraryName with the name of your document library.
- Run the script.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)