Hi @AB123 ,
I have found this which shows how to read from a CSV file and create SharePoint groups and add members for your reference.
After this, you could take folder names from a CSV file and creates folders.
Like this:
Please try to use this code:
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Ops"
$CSVFilePath = "C:\Temp\Folders.csv"
$LibraryName = "Documents"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$Web = Get-PnPWeb
#Get the Document Library and its site relative URL
$Library = Get-PnPList -Identity $LibraryName -Includes RootFolder
If($Web.ServerRelativeUrl -eq "/")
{
$LibrarySiteRelativeURL = $Library.RootFolder.ServerRelativeUrl
}
else
{
$LibrarySiteRelativeURL = $Library.RootFolder.ServerRelativeUrl.Replace($Web.ServerRelativeUrl,'')
}
#Get the CSV file
$CSVFile = Import-Csv $CSVFilePath
#Read CSV file and create folders
ForEach($Row in $CSVFile)
{
#Replace Invalid Characters from Folder Name, If any
$FolderName = $Row.FolderName
$FolderName = [RegEx]::Replace($FolderName, "[{0}]" -f ([RegEx]::Escape([String]'\"*:<>?/\|')), '_')
#Frame the Folder Name
$FolderURL = $LibrarySiteRelativeURL+"/"+$FolderName
#Create Folder if it doesn't exist
Resolve-PnPFolder -SiteRelativePath $FolderURL | Out-Null
Write-host "Ensured Folder:"$FolderName -f Green
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Reference:
PowerShell to Bulk Create Folders in a Document Library from a CSV File
Microsoft provides third-party contact information to help you find additional information about this topic. This contact information may change without notice. Microsoft does not guarantee the accuracy of third-party contact information.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.