question

frob avatar image
0 Votes"
frob asked frob commented

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

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.

office-sharepoint-onlinewindows-server-powershellsharepoint-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoyZ avatar image
0 Votes"
JoyZ answered frob commented

@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="julie@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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JulieWang-MSFT

This approach is fine as well. However, will it be possible via PowerShell to carry over permissions as well?

Thank you so much.

0 Votes 0 ·

@frob,

Copy files do not retain permissions, and all files inherit the library permissions by default after copying.

We suggest you re-grant permissions for those files after copying.

0 Votes 0 ·

@frob,

I’m checking how the things are going on about this issue.

Please feel free to reply if there is any update.

0 Votes 0 ·

Hi @JulieWang-MSFT
I am hoping that someone might have the PowerShell script to retain the permissions as well (on top of the script you gave me to copy).
Will be great if we leave this thread open.

Thank you so much for checking.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered cheong00 commented

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Reply to the user who reported this thread:

I've suspended the account before, and the account is still suspended. Have no idea why the account can still posting.

Have added feedback and let the site admins follow-up the issue.

0 Votes 0 ·

A follow-up for the reporting user.

https://docs.microsoft.com/en-us/answers/idea/515713/index.html

So I believe you can directly comment below the answers you think is invalid, or if you prefer you can also report it the old way and I'll try to comment below when I see it. (And other moderators may just delete it, I don't know)

0 Votes 0 ·