pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
200 stars 140 forks source link

Invoke-PnPSiteTemplate: Object reference not set to an instance of an object. #822

Open aybouzaglou opened 1 year ago

aybouzaglou commented 1 year ago

I'm getting the following error when trying to import a PNP template. I'm using PowerShell 7.3.1

Get-PnPException is: Message : Object reference not set to an instance of an object. Stacktrace : at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 79 at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPSharePointCmdlet.cs:line 121 at System.Management.Automation.CommandProcessor.ProcessRecord() ScriptLineNumber : 1

whitehotaru commented 1 year ago

I have a similar issue, @erwinvanhunen After creating a XML PnP-Sitetemplate with Get-PnPSiteTemplate and applying it with Invoke-PnPSiteTemplate I get an access denied error.

PS > Invoke-PnPSiteTemplate -Path ./CUSTOMER-Search-Center-Customization.xml                    
Invoke-PnPSiteTemplate: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
PS > Get-PnPException

Message          : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Stacktrace       :    at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 93
                      at System.Management.Automation.Cmdlet.DoProcessRecord()
                      at System.Management.Automation.CommandProcessor.ProcessRecord()
ScriptLineNumber : 1

My PnP Template is quite simple:

<?xml version="1.0" encoding="utf-8"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2022/09/ProvisioningSchema">
  <pnp:Preferences Generator="PnP.Framework, Version=1.11.2.0, Culture=neutral, PublicKeyToken=0d501f89f11b748c" />
  <pnp:Templates ID="CONTAINER-TEMPLATE-EC63A3A6533D4AA19F07FCA4F1106C96">
    <pnp:ProvisioningTemplate ID="TEMPLATE-EC63A3A6533D4AA19F07FCA4F1106C96" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
      <pnp:SiteSettings AllowDesigner="true" AllowCreateDeclarativeWorkflow="true" AllowSaveDeclarativeWorkflowAsTemplate="true" AllowSavePublishDeclarativeWorkflow="true" SearchBoxInNavBar="Inherit" SearchCenterUrl="https://customertenant.sharepoint.com/sites/somesitecollection/SitePages/search.aspx" />
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

I did set the custom script status with Set-PnPSite -NoScriptSite $false, but get the error anyway. Scripts are allowed on tenant level.

image
$PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Darwin 22.3.0 Darwin Kernel Version 22.3.0: Thu Jan  5 20:53:49 PST 2023; root:xnu-8792.81.2~2/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0