Copy a list - with list items - to another site

Published Apr 01 2021 08:47 AM 2,826 Views
New Contributor

The Problem

Have you ever heard this from a client or colleague?

 

"I have a list of data on this one site that I need to move to another site."

sad-mario.png

 

Just a simple list of data that they want moved from Site A to Site B. For such a simple request, the solution has, historically, always been anything but simple.

 

Until now! Thanks to PnP PowerShell, we can handle this request in 5 lines of PowerShell!

 

The Setup

Aside from the obvious set of SharePoint sites and a list, the only real prerequisite is to make sure you have PnP PowerShell installed.

 

This blog is running the newer PnP.PowerShell module, which I highly recommend you jump over to.

 

You can use the link from the introduction for the full instructions, or you can open up PowerShell and...

 

Install-Module -Name PnP.PowerShell

 

The Solution

In a previous blog post, we walked through the process of creating custom view formats to create a pretty nifty dashboard full of cards about members of the Fellowship of the Ring.

 

For the sake of this example, let's pretend I made a mistake (which never happens IRL), and I put that list on the wrong site.

 

The solution is pretty straightforward. We're basically going to create a PnP site template, add our list data to it, and then apply that template to our target site.

 

Step 1 - Connect to the Source Site

The first thing we'll do is connect to the source site.

 

Connect-PnPOnline -Url https://constoso.sharepoint.com/sites/star-wars -Interactive

 

Step 2 - Create the Template

We actaully have two lists we need to copy. Fellowship Members is the list we care about but, since it contains a lookup column, we need to grab the Middle Earth Locales lookup list as well.

 

Get-PnPSiteTemplate -Out Lists.xml -ListsToExtract "Middle Earth Locales", "Fellowship Members" -Handlers Lists

 

Step 3 - Get the List Data

We'll use the Add-PnPDataRowToSiteTemplate cmdlet to populate our list instances with actual list item. Because we have two lists, we need to run the cmdlet twice. (So, technically, I guess we're doing 6 lines of PowerShell. Shh!)

 

Add-PnPDataRowsToSiteTemplate -Path Lists.xml -List "Middle Earth Locales"

Add-PnPDataRowsToSiteTemplate -Path Lists.xml -List "Fellowship Members"

 

Step 4 - Connect to Target Site

Now we connect to the target site...

 

Connect-PnPOnline -Url https://constoso.sharepoint.com/sites/lotr -Interactive

 

Step 5 - Apply the Template

...and we apply our template using the Invoke-PnPSiteTemplate cmdlet.

 

Invoke-PnPSiteTemplate -Path Lists.xml

 

Game Over

Now you've got your list(s), complete with data, copied over to another site. All that's left to do is get rid of the old one, if necessary.

 

you-win.jpg
1 Comment
Established Member

Thanks for this simple tip to help break me in. Is there something similar for copying pages or page templates from one modern site to another?  

 

Or maybe a crazier request, a script to "convert" a modern Team Site to a Communication Site?

%3CLINGO-SUB%20id%3D%22lingo-sub-2248892%22%20slang%3D%22en-US%22%3ECopy%20a%20list%20-%20with%20list%20items%20-%20to%20another%20site%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2248892%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--496393171%22%20id%3D%22toc-hId--496370164%22%20id%3D%22toc-hId--496370164%22%20id%3D%22toc-hId--496370164%22%20id%3D%22toc-hId--496370164%22%20id%3D%22toc-hId--496370164%22%3EThe%20Problem%3C%2FH2%3E%0A%3CP%3EHave%20you%20ever%20heard%20this%20from%20a%20client%20or%20colleague%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3E%22I%20have%20a%20list%20of%20data%20on%20this%20one%20site%20that%20I%20need%20to%20move%20to%20another%20site.%22%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22sad-mario.png%22%20style%3D%22width%3A%20250px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F268845iC7F4B8A766776878%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22sad-mario.png%22%20alt%3D%22sad-mario.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJust%20a%20simple%20list%20of%20data%20that%20they%20want%20moved%20from%20%3CSTRONG%3ESite%20A%3C%2FSTRONG%3E%20to%20%3CSTRONG%3ESite%20B%3C%2FSTRONG%3E.%20For%20such%20a%20simple%20request%2C%20the%20solution%20has%2C%20historically%2C%20always%20been%20anything%20but%20simple.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUntil%20now!%20Thanks%20to%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpowershell%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EPnP%20PowerShell%3C%2FA%3E%2C%20we%20can%20handle%20this%20request%20in%205%20lines%20of%20PowerShell!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1991119662%22%20id%3D%22toc-hId-1991142669%22%20id%3D%22toc-hId-1991142669%22%20id%3D%22toc-hId-1991142669%22%20id%3D%22toc-hId-1991142669%22%20id%3D%22toc-hId-1991142669%22%3EThe%20Setup%3C%2FH2%3E%0A%3CP%3EAside%20from%20the%20obvious%20set%20of%20SharePoint%20sites%20and%20a%20list%2C%20the%20only%20real%20prerequisite%20is%20to%20make%20sure%20you%20have%20PnP%20PowerShell%20installed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20blog%20is%20running%20the%20newer%3CCODE%3EPnP.PowerShell%3C%2FCODE%3Emodule%2C%20which%20I%20highly%20recommend%20you%20jump%20over%20to.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20the%20link%20from%20the%20introduction%20for%20the%20full%20instructions%2C%20or%20you%20can%20open%20up%20PowerShell%20and...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EInstall-Module%20-Name%20PnP.PowerShell%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-183665199%22%20id%3D%22toc-hId-183688206%22%20id%3D%22toc-hId-183688206%22%20id%3D%22toc-hId-183688206%22%20id%3D%22toc-hId-183688206%22%20id%3D%22toc-hId-183688206%22%3EThe%20Solution%3C%2FH2%3E%0A%3CP%3EIn%20a%20previous%20blog%20post%2C%20we%20walked%20through%20the%20process%20of%20creating%20custom%20view%20formats%20to%20create%20a%20pretty%20nifty%20dashboard%20full%20of%20cards%20about%20members%20of%20the%20%3CEM%3EFellowship%20of%20the%20Ring%3C%2FEM%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20sake%20of%20this%20example%2C%20let's%20pretend%20I%20made%20a%20mistake%20(which%20%3CEM%3Enever%3C%2FEM%3E%20happens%20IRL)%2C%20and%20I%20put%20that%20list%20on%20the%20wrong%20site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20solution%20is%20pretty%20straightforward.%20We're%20basically%20going%20to%20create%20a%20PnP%20site%20template%2C%20add%20our%20list%20data%20to%20it%2C%20and%20then%20apply%20that%20template%20to%20our%20target%20site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--922724686%22%20id%3D%22toc-hId--922701679%22%20id%3D%22toc-hId--922701679%22%20id%3D%22toc-hId--922701679%22%20id%3D%22toc-hId--922701679%22%20id%3D%22toc-hId--922701679%22%3EStep%201%20-%20Connect%20to%20the%20Source%20Site%3C%2FH4%3E%0A%3CP%3EThe%20first%20thing%20we'll%20do%20is%20connect%20to%20the%20source%20site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EConnect-PnPOnline%20-Url%20https%3A%2F%2Fconstoso.sharepoint.com%2Fsites%2Fstar-wars%20-Interactive%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-1564788147%22%20id%3D%22toc-hId-1564811154%22%20id%3D%22toc-hId-1564811154%22%20id%3D%22toc-hId-1564811154%22%20id%3D%22toc-hId-1564811154%22%20id%3D%22toc-hId-1564811154%22%3EStep%202%20-%20Create%20the%20Template%3C%2FH4%3E%0A%3CP%3EWe%20actaully%20have%20two%20lists%20we%20need%20to%20copy.%20%3CEM%3EFellowship%20Members%3C%2FEM%3E%20is%20the%20list%20we%20care%20about%20but%2C%20since%20it%20contains%20a%20lookup%20column%2C%20we%20need%20to%20grab%20the%20%3CEM%3EMiddle%20Earth%20Locales%3C%2FEM%3E%20lookup%20list%20as%20well.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EGet-PnPSiteTemplate%20-Out%20Lists.xml%20-ListsToExtract%20%22Middle%20Earth%20Locales%22%2C%20%22Fellowship%20Members%22%20-Handlers%20Lists%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--242666316%22%20id%3D%22toc-hId--242643309%22%20id%3D%22toc-hId--242643309%22%20id%3D%22toc-hId--242643309%22%20id%3D%22toc-hId--242643309%22%20id%3D%22toc-hId--242643309%22%3EStep%203%20-%20Get%20the%20List%20Data%3C%2FH4%3E%0A%3CP%3EWe'll%20use%20the%3CCODE%3EAdd-PnPDataRowToSiteTemplate%3C%2FCODE%3Ecmdlet%20to%20populate%20our%20list%20instances%20with%20actual%20list%20item.%20Because%20we%20have%20two%20lists%2C%20we%20need%20to%20run%20the%20cmdlet%20twice.%20(So%2C%20technically%2C%20I%20guess%20we're%20doing%206%20lines%20of%20PowerShell.%20Shh!)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EAdd-PnPDataRowsToSiteTemplate%20-Path%20Lists.xml%20-List%20%22Middle%20Earth%20Locales%22%0A%0AAdd-PnPDataRowsToSiteTemplate%20-Path%20Lists.xml%20-List%20%22Fellowship%20Members%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId--2050120779%22%20id%3D%22toc-hId--2050097772%22%20id%3D%22toc-hId--2050097772%22%20id%3D%22toc-hId--2050097772%22%20id%3D%22toc-hId--2050097772%22%20id%3D%22toc-hId--2050097772%22%3EStep%204%20-%20Connect%20to%20Target%20Site%3C%2FH4%3E%0A%3CP%3ENow%20we%20connect%20to%20the%20target%20site...%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EConnect-PnPOnline%20-Url%20https%3A%2F%2Fconstoso.sharepoint.com%2Fsites%2Flotr%20-Interactive%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH4%20id%3D%22toc-hId-437392054%22%20id%3D%22toc-hId-437415061%22%20id%3D%22toc-hId-437415061%22%20id%3D%22toc-hId-437415061%22%20id%3D%22toc-hId-437415061%22%20id%3D%22toc-hId-437415061%22%3EStep%205%20-%20Apply%20the%20Template%3C%2FH4%3E%0A%3CP%3E...and%20we%20apply%20our%20template%20using%20the%3CCODE%3EInvoke-PnPSiteTemplate%3C%2FCODE%3Ecmdlet.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-powershell%22%3EInvoke-PnPSiteTemplate%20-Path%20Lists.xml%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2071126987%22%20id%3D%22toc-hId--2071103980%22%20id%3D%22toc-hId--2071103980%22%20id%3D%22toc-hId--2071103980%22%20id%3D%22toc-hId--2071103980%22%20id%3D%22toc-hId--2071103980%22%3EGame%20Over%3C%2FH2%3E%0A%3CP%3ENow%20you've%20got%20your%20list(s)%2C%20complete%20with%20data%2C%20copied%20over%20to%20another%20site.%20All%20that's%20left%20to%20do%20is%20get%20rid%20of%20the%20old%20one%2C%20if%20necessary.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20style%3D%22text-align%3A%20center%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22you-win.jpg%22%20style%3D%22width%3A%20504px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F268844i45293B9FF32CD4E9%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22you-win.jpg%22%20alt%3D%22you-win.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2248892%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22tetris.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F268841i67DF207C7F6728D0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22tetris.jpg%22%20alt%3D%22tetris.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHave%20a%20SharePoint%20list%20full%20of%20valuable%20data%20but%20you%20need%20it%20copied%20to%20another%20site.%20Let's%20get%20moving!%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2248892%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EGetting%20started%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHow%20to%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2719249%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20a%20list%20-%20with%20list%20items%20-%20to%20another%20site%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2719249%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20this%20simple%20tip%20to%20help%20break%20me%20in.%20Is%20there%20something%20similar%20for%20copying%20pages%20or%20page%20templates%20from%20one%20modern%20site%20to%20another%3F%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20maybe%20a%20crazier%20request%2C%20a%20script%20to%20%22convert%22%20a%20modern%20Team%20Site%20to%20a%20Communication%20Site%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Apr 01 2021 08:47 AM
Updated by: