Hi @SteveH,
Thank you for posting in this community.
Here I am using PnP PowerShell to copy the structure of a website to another website. This PnP PowerShell only copies the structure of the source website and not the content. Also, you can’t extract the site template of a root site and apply it on subsites.
Prerequisites: Install PnP PowerShell
Check if the classic PnP PowerShell module is installed with the below command:
Get-Module SharePointPnPPowerShellOnline -ListAvailable | Select-Object Name,Version
This returns the Name and version of legacy PnP PowerShell installed on the machine (If any). Uninstall Any previous PnP PowerShell Modules for SharePoint Online installed:
Uninstall-Module SharePointPnPPowerShellOnline -Force -AllVersions
Install the New PnP PowerShell Module:
Install-Module PnP.PowerShell
If you need install PnP PowerShell offline, you can also use setup files Download the PnP PowerShell Offline Installation package and install it with:
Install-Package C:\Path\File.nupkg
Step1: Get the Source Site Schema XML
This cmdlet gets all artifacts from the source site, such as content types, site columns, term store, list and libraries, theme, pages, etc., into the given template XML file. We also have a switch -includesitegroups to include site security so that your target site will have unique permissions.
#Set variables
$SiteURL = "Your source site url"
$SchmaXMLPath = "YourPath\SiteSchema.xml"
#Connect to PnP Online
Connect-PnPOnline -Url $siteUrl -Interactive
#Get Site Schema
Get-PnPSiteTemplate -Out ($SchmaXMLPath) -PersistBrandingFiles -PersistPublishingFiles
Step 2: Create a New Site Collection or Subsite
I notice you have already done this step, so you can skip it then. I added this step here to ensure the integrity of the process of copying the site.
Step 3: Apply the Site Schema into Target Site
#Set variables
$SiteURL = "Your target site url"
$SchmaXMLPath = "Your Path\SiteSchema.xml"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Apply Pnp Provisioning Template
Invoke-PnPSiteTemplate -Path $SchmaXMLPath -ClearNavigation
If you need to copy the content of the website, then you can save the original website as a template while including his content and then use this template to create the target website. Refer to this thread for the exact steps.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.