Copy site from one tenant to another using a template is giving an "access denied" error

Occasional Visitor

Hello everyone,


I need to replicate a site from one tenant to another. For that, I'm following the steps in C-Sharp Corner, which consists in two simple code snippets:

Export site template from original tenant

$SourceSiteURL = ""
$XMLTemplatePath = "C:\Site Templates\DemoSiteTemplate.xml"

#Connect to source SharePoint
Connect-PnPOnline -Url $SourceSiteURL -Interactive

#Export site template to specified path
Get-PnPSiteTemplate -Out ($XMLTemplatePath)

#Disconnect source SharePoint

Import site template to destination tenant

$DestinationSiteURL = ""
$XMLTemplatePath = "C:\Site Templates\DemoSiteTemplate.xml"

#Connect to PnP Online
Connect-PnPOnline -Url $DestinationSiteURL -Interactive

#Apply SharePoint template
Invoke-PnPSiteTemplate -Path $XMLTemplatePath -ClearNavigation

#Disconnect source SharePoint

Exporting the template works great; however, when trying to apply the template in the destination site, the following error appears:

Invoke-PnPSiteTemplate : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ Invoke-PnPSiteTemplate -Path $XMLTemplatePath -ClearNavigation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-PnPSiteTemplate], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate

I have admin permissions on both tenants already. What could possibly be causing this error?

0 Replies