Microsoft 365 – SharePoint Online – resolving error – Invoke-PnPSiteTemplate – Cannot enable the site collection app catalog feature in this site collection because it has not been approved by the tenant admin
Hi All,
Greetings for the day!!! Today new issue and solution 🙂
Background / Details
- For one of our Microsoft 365 application, we are preparing custom template from base site for creating multiple site collection from the respective template
- So we have created our base communication site
- We did customization as per our requirement
- Then we used PnP CMDLETS to get / provision the template with following steps
- We have our one custom SPFx component as well
- We planned to deploy this SPFx component at site collection level only
- So the base site from which we need to provision template, we have enabled app catalog by using POWERSHELL CMDLET – Add-SPOSiteCollectionAppCatalog
Add-SPOSiteCollectionAppCatalog
-Site <SpoSitePipeBind>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
- Detailed article – Add-SPOSiteCollectionAppCatalog
- But later we changed the approach and we deployed our SPFx component at tenant level so that it will be available for all sites in tenant
- So we again removed the site collection app catalog (Very important to know – this dosent removes the library “Apps for SharePoint” it only disables the deployment of new SPFx component) we used following PowerShell CMDLET
Remove-SPOSiteCollectionAppCatalog
[-Site]
- Detailed article – Remove-SPOSiteCollectionAppCatalog
STEPS to get / generate / provision the site template from existing site
- Connect to the site from which we need to get the template – Connect-PnPOnline
- Here, siteURL – URL of the site of which we need to get the template
- We will use Connect-PnPOnline to connect our SharePoint Online site as
Connect-PnPOnline -url $siteURL -Credentials $cred
- Once we connected successfully to our respective base SharePoint site, we will use Get-PnPSiteTemplate CMDLET to get the template as in below code
- We can generate / provision site template in two file formats – XML and PnP
- Here we are using XML format
Get-PnPSiteTemplate -Out "PnP-Provisioning-File.xml"
- As in above CMDLET –out parameter specifies the PATH where our site template (provisioning template) will be stored
- As we successfully get site template, it looks like
- For above generated XML file / template, XML schema used in the example references the 201909 version of the PnP provisioning schema, which has been defined together with the SharePoint PnP Community, and which can be found on GitHub at PnP-Provisioning-Schema.
Next step is to apply the respective site template on require existing site collections or new site collection
STEPS to apply site template / provisioning template
- Consider we have created new site collection and we want to apply the respective provisioning template
- We will connect to the respective site collection on which we need to apply the provisioning template as
- Here, $siteURL – will be site collection on which we need to apply the our created site template / provisioning template
Connect-PnPOnline -url $siteURL -Credentials $cred
- As we connected to respective site collection, we will use Invoke-PnPSiteTemplate CMDLET to apply the template as
Invoke-PnPSiteTemplate -Path "PnP-Provisioning-File.xml"
- While applying the template, we got an error / issue and it didnt worked successfully
Issue / Error
Invoke-PnPSiteTemplate : Cannot enable the site collection app catalog feature in this site collection
because it has not been approved by the tenant admin
At line:2 char:5
- Invoke-PnPSiteTemplate -Path “C:\PnP-Provisioning-File.xml”
~~~~~~~~~~~~- CategoryInfo : InvalidOperation: (:) [Invoke-PnPSiteTemplate], PSInvalidOperationException
- FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Provisioning.Site.InvokeSiteTemplat
e
Solution
- I am bit wondering for this error as we already removed app catalog for our base site collection from which we provisioned the template
- This issue happens because we enabled app catalog for our base site collection and removed again
- Here, removing app catalog from site collection does not remove the “Apps for SharePoint” library, it just makes the Apps non functional and restricts the deployment of new apps
- So there are two approaches to make apply template successfully or to make execution of CMDLET – Invoke-PnPSiteTemplate
- Enable the app catalog for site collection again, provision new template and try to apply it again
- Update the template xml file – remove list instance of “Apps for SharePoint” library as shown in below figure
- I went for 2nd approach – updated the template file – removed the
I hope this will help and will save time as well
REFERENCES
- Introducing the PnP provisioning engine
- Add-SPOSiteCollectionAppCatalog
- Remove-SPOSiteCollectionAppCatalog
Thanks for reading!!! HAVE a FANTASTIC LEARNING 🙂 LIFE IS BEAUTIFUL 🙂
You must be logged in to post a comment.