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?
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
3.When you click list template gallery, you can see the library template you just created.
4.Select this template and click on Download a Copy under the FILES tab
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.
7.Then, go to Site contents page(classic mode). Click add an app, in the "Find an app" searchbox, entry template name.
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.
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: