Step-by-Step Guide to Copy Pages between SharePoint Online

Unfortunately you can’t copy pages in SharePoint through the UI. But sometimes you may need to copy pages and their associated SiteAssets from one SiteCollection to another.
This blog post will guide you through a PnP-PowerShell script that automates this process, making it easier and more efficient.
Let’s break down the script and look each step:
Prerequisites
Before running the script, make sure you have:
- PnP-PowerShell module installed
- Appropriate permissions for both source and destination sites
Step-by-Step Breakdown
1. Setting Up Variables
|
|
These variables store important information like authentication details, site URLs, and the IDs of pages to be copied.
2. Connecting to SharePoint Sites
|
|
These lines establish connections to both the source and destination SharePoint sites using the PnP-PowerShell cmdlets.
3. Processing Each Page
The script then loops through each page provided by ID and checks if the page exists in the source site. If the page exists, it proceeds to copy the page and its SiteAssets:
|
|
4. Copying the Page and Assets
For each page, the script:
- Gets the file reference and name
- Determines the corresponding folder in SiteAssets
- Copies the SiteAssets folder to the destination site
- Exports the page from the source site
- Imports the page to the destination site
|
|
5. Cleaning Up
Finally, the script disconnects from both SharePoint sites:
|
|
Complete Script
Here’s the complete script for your reference:
|
|
This script provides an efficient way to copy SharePoint pages and their associated SiteAssets between sites. By automating this process, you can save time instead of manually recreating pages.
Remember to replace the placeholder values for $SourceSiteUrl and $DestinationSiteUrl with your actual SharePoint environment Url’s before running the script.
If you have problems copying your pages, it might make sense to also give third-party tools like ShareGate or AvePoint a try.
I hope this guide and script helps you to copy your pages and SiteAssets between SharePoint sites.
If you have any questions or suggestions, feel free to leave a comment below.
Published on:
Learn moreWe can help you with Step-by-Step Guide to Copy Pages between SharePoint Online
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
Creating Copilot Studio Agents Without an M365 Copilot Premium License
A common assumption when getting started with Copilot Studio is that you need a full Microsoft 365 Copilot Premium license. That assumption is...
Power Automate: Get events (V4) shared mailbox fix
When your flow reads a shared mailbox calendar using the Office 365 Outlook → Get events (V4) connector, it can fail in a way that looks like...
Using Managed Identity with Azure Automation & PnP.PowerShell
How to Set Up a Managed Identity for Azure Automation Runbooks and Use It in PowerShell Scripts with PnP.PowerShell This guide walks you throu...
UPDATED - Set Up Pay-as-you-go M365 Chat & SharePoint Agents
Introduction to Pay-as-You-Go Agents in Microsoft 365 Microsoft has introduced a flexible way for organizations to leverage AI capabilities wi...
How to Use Flexible Sections in SharePoint Pages and News
If you’ve been using SharePoint Online to build pages or share news, you know how important it is to have a layout that works for your c...
What's New in SharePoint Pages
1. New Carousel Layout in the Hero Web Part The Hero Web Part has always been a fundamental element of SharePoint pages. The new Carousel Layo...
Power Platform Solutions Made Simple
Introduction to Power Platform Solutions Power Platform Solutions offer many benefits, especially when moving from standalone flows and apps t...
Use your Bluesky post for comments on your Hugo Blog
Since Bluesky is getting really popular by people I interact with, I decided to switch my blog comments to Bluesky posts. In this blog post, I...
Exploring SharePoint Online's SiteAssets Library
The SiteAssets library in SharePoint Online often seems like a mystery to a lot of users I talk to, but it’s important to understand it ...
Re-creating Multilanguage Links: A Step-by-Step Guide
Maybe you’ve also stumbled upon the issue of missing multilanguage links in your SitePages library in SharePoint Online. This can happen...