
@frob ,
We could not convert a folder into a Document Library and keep all the content and permissions in document library as they are.
As a workaround, we could get all the folders name in the original library, then create new libraries with those folder names, after that, copy files from old folders to new document library, however, this will not maintain permissions.
$SiteUrl="https://tenant.sharepoint.com/sites/Team1"
$UserName="******@tenant.onmicrosoft.com"
$cred = Get-Credential -UserName $UserName -Message "Please enter password for $UserName"
Connect-PnPOnline -Url $SiteUrl -Credentials $cred
#Site Relative Path of the document Library
$ParentFolderURL = "/Library824"
$AllFolders= Get-PnPFolderItem -ItemType Folder -FolderSiteRelativeUrl $ParentFolderURL | Where {($_.Name -ne "Forms") -and (-Not($_.Name.StartsWith("_")))}
ForEach($Folder in $AllFolders) {
New-PnPList -Title $Folder.Name -Template DocumentLibrary
$newFolderURL = $ParentFolderURL+"/"+$Folder.Name
$AllFiles = Get-PnPFolderItem -FolderSiteRelativeUrl $newFolderURL -ItemType File
ForEach($File in $AllFiles){
$SourceUrl = $File.ServerRelativeUrl
$TargetURL="/sites/Team1/"+$Folder.Name+"/"+$File.Name
Copy-PnPFile -SourceUrl $SourceUrl -TargetUrl $TargetURL -Force
}
}
If an Answer is helpful, please click "Accept Answer" and upvote it.
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.