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 moreRelated posts
Silently Update SharePoint Metadata with PnP PowerShell
Why Bother with Metadata? Think of metadata as the DNA of your SharePoint content. It tells you who created a document, when it was last touch...
New Editing Options for Image Web Part in SharePoint Online
Adding and Editing Images with the Image Web Part The Image web part simplifies the process of adding visual elements to your SharePoint Onlin...
External User Access Reviews in Office 365
Understanding External User Access Before diving into the reviews, it’s important to understand what external access entails. External u...
Power Automate - How-to Posting on BlueSky and Mastodon
Introduction Do you want to save time and effort by automating your social media posts across different platforms? Do you want to learn how to...
M365 Groups: Set Up a 'No Owner Policy' & why it's Important
Introduction Managing group ownership is crucial for maintaining order and security within an organization in Microsoft 365. A “No Owner...
Social media content creator with AI Promts
Prerequisites For this tutorial you need the following: A premium Power Automate account, e.g. a Power Automate per user plan or an Powerapps...
Change SharePoint group to Security Groups with PowerShell
Automating SharePoint Permissions with PowerShell Managing SharePoint user permissions can be a complex and time-consuming task, especially fo...
Deleting doublettes in SharePoint list with PnP PowerShell
In this blog post, I will break down a PnP PowerShell script that is designed to connect to a SharePoint site, retrieve a list of users from a...
Limit Copilot's access to SharePoint Sites and Content
Why Permissions in Office365 matter for Copilot In the ever changing digital landscape, managing permissions and ensuring data security are pa...
Microsoft Teams Channel Types: How to Choose the Right One
Introduction Microsoft Teams is a powerful collaboration tool that allows you to communicate, share, and work with your team members in a secu...