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."
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!
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
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.
The first thing we'll do is connect to the source site.
Connect-PnPOnline -Url https://constoso.sharepoint.com/sites/star-wars -Interactive
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
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"
Now we connect to the target site...
Connect-PnPOnline -Url https://constoso.sharepoint.com/sites/lotr -Interactive
...and we apply our template using the Invoke-PnPSiteTemplate
cmdlet.
Invoke-PnPSiteTemplate -Path Lists.xml
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.