How to Copy a List in SharePoint Online?
Requirement: Copy a List in SharePoint Online.
How to Copy a SharePoint Online List?
If you’re working in SharePoint Online, there may be times when you need to duplicate a list. Maybe you want to make a copy of an existing list for testing purposes, or perhaps you need to create multiple lists with similar information. Whatever the reason, duplicating a list is a quick and easy process. This article will show you how to duplicate a list in SharePoint Online. Let’s get started!
The modern SharePoint Online sites provide a nifty way to create a list from existing lists. Here is how to make a copy of a list in SharePoint Online:
- Go to the SharePoint site where the source list is located.
- From the Home page, click on the “New” button and then choose “List” in the toolbar at the top of the page. You can also go to the “Site Contents” Page (Click on “Settings” gear >> Choose “Site Contents”), click on the “New” menu, and choose “List”.
- This opens a new list creation page, which provides an option to create a new list from the existing list. “Create a list” page. Click on the “From existing list” button on the page.
- Select the source list to clone and click on the “Next” button on the bottom to copy the existing list structure. You can pick a list from different site collections even!
- Provide a name to your new list, and click on “Create” to complete the process.
The new list will be created with all of the same fields as the original list. The above method copies the structure of the list without copying any data from it! How about copying lists between sites with data? BTW, You can use the “Content and Structure” page (/_layouts/15/sitemanager.aspx) to move or copy items between lists.
Copy a List or Document Library using PnP PowerShell
Use the Copy-PnPList cmdlet to copy a list or document library in SharePoint Online. This cmdlet copies the fields, views, and settings of the list (But does not copy along the list items in the list!).
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail/"
$SourceListName = "Documents"
$DestinationListName = "Documents Backup"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Copy the list using PnP powershell
Copy-PnPList -Identity $SourceListName -Title $DestinationListName
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Similarly, to copy a list to another site, use:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail/"
$SourceListName = "Documents"
$DestinationSiteURL = "https://crescent.sharepoint.com/sites/Sales/"
$DestinationListName = "Documents Backup"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Copy list to another site using powershell
Copy-PnPList -Identity $SourceListName -Title $DestinationListName -DestinationWebUrl $DestinationSiteURL
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
SharePoint Online: Copy List from one site to another using PowerShell
Copying a SharePoint list from one site to another manually can be time-consuming and error-prone. But with PowerShell, it’s easy to automate the process! Let me show you how to use PowerShell to copy a SharePoint list with content from one site to another.
#Parameters
$SourceSiteURL = "https://crescent.sharepoint.com/sites/Retail"
$TargetSiteURL = "https://crescent.sharepoint.com/sites/Sales"
$ListName= "Projects"
$TemplateFile ="$env:TEMP\Template.xml"
#Connect to the Source Site
Connect-PnPOnline -Url $SourceSiteURL -Interactive
#Create the Template
Get-PnPSiteTemplate -Out $TemplateFile -ListsToExtract $ListName -Handlers Lists
#Get Data from source List
Add-PnPDataRowsToSiteTemplate -Path $TemplateFile -List $ListName
#Connect to Target Site
Connect-PnPOnline -Url $TargetSiteURL -Interactive
#Apply the Template
Invoke-PnPSiteTemplate -Path $TemplateFile
If your list is using any lookup fields, make sure you copy the parent list first! Otherwise, you may run into “Invoke-PnPSiteTemplate : Value does not fall within the expected range.” error.
Here is another post on copying the items in the list, use: Copy items from one list to another in SharePoint Online using PowerShell
I just wanted to add that if someone gets an error related to the scope while trying to execute this script, you can add after line 14:
(Get-Content -path $TemplateFile) -replace ‘RootSite’,’Web’ | Set-Content -Path $TemplateFile
Thanks!