question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke-PnPSiteTemplate throws Access denied error on SiteSettings

See original GitHub issue

Expected behavior Execute without issue

Actual behavior Invokes the site template correctly, except for site settings. The quick navigation is not provisioned successfully.

If I add the following switch to Get-PnPSiteTemplate and Invoke-PnPSiteTemplate, the site template succeeds: -ExcludeHandlers SiteSettings. I need to add the quick launch manually afterwards.

Steps to reproduce behavior

$connection = Connect-PnPOnline -Url $url -Credentials $credPnP -ReturnConnection -ErrorAction Stop 
$siteConnection = Connect-PnPOnline -Url $siteUrl -Credentials $credPnP -ReturnConnection -ErrorAction Stop 
Get-PnPSiteTemplate -Connection $connection -Out $templateXmlName -IncludeAllPages -PersistBrandingFiles -Force
Invoke-PnPSiteTemplate -Connection $siteConnection -Path $templateXmlName -IgnoreDuplicateDataRowErrors -OverwriteSystemPropertyBagValues -ClearNavigation 

Invoke-PnPSiteTemplate: Access denied. You do not have permission to perform this action or access this resource. Full exception below.

What is the version of the Cmdlet module you are running? PnP.PowerShell version 1.5.0

Which operating system/environment are you running PnP PowerShell on? Errors are received locally as well as in Azure RunBook / Azure Function

Exception In Dutch, apologies, but it says “Access Denied”. It looks like it’s on the check for feature activation; nevertheless, the features are properly activated.

Message          : Toegang geweigerd. U bent niet gemachtigd om deze bewerking uit te voeren of deze bron te openen.
Stacktrace       :    bij Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
                      bij Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
                      bij Microsoft.SharePoint.Client.ClientRequest.<ExecuteQueryToServerAsync>d__53.MoveNext()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task
                   )
                      bij Microsoft.SharePoint.Client.ClientRequest.<ExecuteQueryAsync>d__39.MoveNext()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task
                   )
                      bij Microsoft.SharePoint.Client.ClientRuntimeContext.<ExecuteQueryAsync>d__65.MoveNext()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task
                   )
                      bij Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__28.MoveNext()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__6.MoveNext
                   ()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task
                   )
                      bij Microsoft.SharePoint.Client.FeatureExtensions.<IsFeatureActiveInternal>d__12.MoveNext()
                   --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
                      bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task
                   )
                      bij Microsoft.SharePoint.Client.FeatureExtensions.IsFeatureActive(Web web, Guid featureID)
                      bij Microsoft.SharePoint.Client.SiteExtensions.IsCommunicationSite(Site site)
                      bij PnP.Framework.Provisioning.ObjectHandlers.ObjectSiteSettings.ProvisionObjects(Web web, Provis
                   ioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInforma
                   tion)
                      bij PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web we
                   b, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo, Boolean
                   calledFromHierarchy, TokenParser tokenParser)
                      bij PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplate.ExecuteCmdlet()
                      bij PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()

Linked issue: https://github.com/pnp/pnpframework/issues/193

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jackpozcommented, Jun 2, 2021

@klaaslauwers as a workaround you could remove the pnp:SiteSettings section from the template

0reactions
klaaslauwerscommented, Jun 29, 2021

Hi @pieronegri,

I don’t want to exclude handlers; the site security is one of the things that is really needed 😃. I’m forced to schedule the script in a cronjob on a Unix server; awaiting the fix in Azure RunBooks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invoke-PnPSiteTemplate: Access denied. · Issue #193
Running Invoke-PnPSiteTemplate to implement a PnP Site Template ... Invoke-PnPSiteTemplate throws Access denied error on SiteSettings #357.
Read more >
Copy site from one tenant to another using a template is ...
Copy site from one tenant to another using a template is giving an "access denied" error. Discussion Options.
Read more >
Fix "Sorry, You don't have access" Access Denied Error on ...
Solution: · Login to SharePoint Online Admin Center · Click on Settings from the left navigation >> Scroll down to “Custom Script” section...
Read more >
How to fix "Access denied" errors when running "Set ...
This error is thrown on some sites, but not all. This happens despite you having global administrator permissions on the tenant. What gives?...
Read more >
applying provisioning template throws "Access denied ...
I am currently facing a strange behaviour with the SharePoint provisioning engine. I am targeting a SharePoint 2019 on-premise version.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found