How to copy a SharePoint Online Document Library from one site to another via PowerShell

I can easily see that from the UI, there are "copy to" and "move to" options for Libraries. But I would like to use PowerShell to copy an entire library from one site to another site, so that when I preview the new site, the library is setup with the same library title, and URL name that was provided from the original library. Example

https://custom.sharepoint.com/sites/home/kitchen-library/ //kitchen-library copies to. https://custom.sharepoint.com/sites/apartments/ //and becomes. https://custom.sharepoint.com/sites/apartments/kitchen-library/ //and all the original kitchen-library files are copied here too 
Is this this possible today via Powershell? asked May 12, 2021 at 22:49 1,363 5 5 gold badges 29 29 silver badges 57 57 bronze badges

1 Answer 1

We recommend that you use SharePoint Online OOB to implement your design.

Please following steps:

1.Go to the source Document library as an admin >> Library settings >> (General Settings) Save document library as template

2.On the Save as Template page, please select "Include Content" option

enter image description here

3.When you click list template gallery, you can see the library template you just created.

enter image description here

4.Select this template and click on Download a Copy under the FILES tab

enter image description here

5.Go to the destination Site Settings page >> (Web Designer Galleries) List templates

6.Click on Upload Document under the FILES tab, upload the template file just downloaded.

enter image description here

7.Then, go to Site contents page(classic mode). Click add an app, in the "Find an app" searchbox, entry template name.

enter image description here

8.Create a name for your new Document library. You will find that the source Document library is completely copied to the new Document library.

enter image description here

If you cannot see Save documnet library/list as template in SharePoint, please enable custom script feature.

Please run the below PowerShell command as an admin:

$TenantURL = "https://tenant-admin.sharePoint.com" $SiteURL ="https://tenant.sharepoint.com/sites/yoursite" $username = "[email protected]" $cred = Get-Credential -UserName $username -Message "Type the password:" Connect-SPOService -URL $TenantURL -Credential $cred Set-SPOSite -Identity $SiteURL -DenyAddAndCustomizePages $False 

Here is a similar case for your reference: