How to copy/migrate folders so they become Document Libraries, retaining content and permissions? (SharePoint Online)

frob 4,261 Reputation points
2021-08-24T20:45:52.203+00:00

Hi there

Is there any PowerShell or other way?

I have around 80 folders in my Shared Documents, and each of these 80 folders should become a document library.

E.g.
http://sp.sharepoint.com/shared documents/FinanceDocs/
should become
http://sp.sharepoint.com/FinanceDocs/
(Will keep all the content and permissions in Finance as they are, applying them on the document library level, of course).

Thank you.

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JoyZ 18,111 Reputation points
    2021-08-25T08:06:54.393+00:00

    @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.


  2. Limitless Technology 39,931 Reputation points
    2021-08-25T11:21:38.763+00:00

    Hello frob,

    Thank you for your question.

    Folders are on by default, but if they're off and you have permissions, follow these steps:

    Open the library where you want to start adding folders.

    Select Settings Gear shaped settings button , and then select Library Settings.

    Select Advanced settings.

    In the Folder section, for Make "New Folder" command available,make sure that the Yes option is selected.

    Select OK, and navigate back to your library.

    For more information you can visit this link:
    https://support.microsoft.com/en-us/office/create-a-folder-in-a-document-library-3d6a8c11-2490-4d6b-8837-f25649a69c56

    If the reply was helpful,please don't forget to upvote or accept as answer.

    Thanks,

    Aradhya C


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.