Forum Discussion
RJF61
Jan 18, 2023Copper Contributor
Copy SharePoint List and Data
I have a SharePoint List where I am making some updates to columns, etc. Is there a way to copy ALL data from one list to another? I have duplicated the list structure but now need to copy information (including CreatedBy, Created) to the new list. How is this best accomplished?
- SvenSieverdingBronze Contributor
Hi RJF61 ,
that more complicated powershell script that copies the values of every source item including created and modified would look like thisConnect-PnPOnline https://tenant.sharepoint.com/sites/SourceSite -Interactive $itemData= Get-PnPListItem -List "SourceListName" Connect-PnPOnline https://tenant.sharepoint.com/sites/TargetSite -Interactive $itemData| foreach-object { Add-PnPListItem -List "TargetListName" -Values @{ "Title"=$_.FieldValues.Title; "YourOtherColumn"=$_.FieldValues.YourOtherColumn; ..... Created=$_.FieldValues.Created; Modified=$_.FieldValues.Modified; Author=$_.FieldValues.Author.Email; Editor=$_.FieldValues.Editor.Email; } }
You have to enter the rest of your columns in line 11 and following
Best Regards,
Sven - SvenSieverdingBronze Contributor
Hi RJF61
you can use PnP Powershell for that
Connect-PnPOnline https://tenant.sharepoint.com/sites/SourceSite -Interactive Get-PnPSiteTemplate listtemplate.pnp -Handlers Lists -ListsToExtract "<List Name>" Add-PnPDataRowsToSiteTemplate .\listtemplate.pnp -List "<List Name>" Connect-PnPOnline https://tenant.sharepoint.com/sites/TargetSite -Interactive Invoke-PnPSiteTemplate .\listtemplate.pnp
But that does not copy the created and modified information... these columns will have the value of you and now.
If we create a more complicated powershell script that copies the values of every source item into a csv file and then insert these items into the new list, we can overwrite the modified and created information. But that script will need to be more tailored to a specific list.
Or you need to use a third party tool like ShareGate.
Best Regards,
Sven