Forum Discussion
Creating site collections using Office Dev PnP provisioning framework fails
For our customers we are provisioning SharePoint sites using the Office Dev PnP materials. For our solutions we prefer provisioning using the Provisioning Schema above using the Office Dev PnP PowerShell commands, therefor we are transferring as much PowerShell code into our provisioning templates. At the moment I am trying to transfer our site collection creation meganism from PowerShell to the provisioning schema, but run into errors.
In the past I was creating Site Collections using the Office Dev PnP New-SPOTenantSite command. On the documentation of the Office Dev PnP Provisioning Schema, located at https://github.com/OfficeDev/PnP-Provisioning-Schema/blob/master/ProvisioningSchema-2016-05.md#sitecollection, I found that also an element regarding Site Collections do exist. Based on the information I've created this small provisioning template:
<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2016/05/ProvisioningSchema">
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.5.1606.1, Culture=neutral, PublicKeyToken=3751622786b357c2" />
<pnp:Sequence SequenceType="Synchronous" ID="PROJECT-SEQUENCE">
<pnp:SiteCollection Language="1043"
SiteTemplate="STS#0"
PrimarySiteCollectionAdmin="MyAdmin@MyTentant.onmicrosoft.com"
MembersCanShare="true"
TimeZone="4"
Title="Test Site from PnP provisioning schema"
Url="https://MyTentant.sharepoint.com/sites/testSiteFromProvisioningSchema">
</pnp:SiteCollection>
</pnp:Sequence>
</pnp:Provisioning>
When I execute the following command, I'm presented with a NullReferenceException
$O365Cred = Get-Credential "MyAdmin@MyTentant.onmicrosoft.com"
Connect-SPOnline -Url "https://MyTentant-admin.sharepoint.com" -Credentials $O365Cred
Apply-SPOProvisioningTemplate -Path .\SiteCollectionTemplate.xml
Apply-SPOProvisioningTemplate : Object reference not set to an instance of an object.
At line:1 char:1
+ Apply-SPOProvisioningTemplate -Path .\SiteCollectionTemplate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Apply-SPOProvisioningTemplate], NullReferenceException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Branding.ApplyProvisioningTemplateAny idea why this happens?
Is creating site collections also supported using the Office Dev PnP Provisioning Engine?
6 Replies
Hi HaroldvandeKamp,
Are you trying to create the site collection with the apply-SPOProvisioningTemplate?
Apply-SPOProvisioningTemplate expects an existing site collection with a root web to apply the template to. The templates that you apply should be genrated with the same base template used as where you apply the template to.
So for example is your template is generated from a team site then you will need to make sure that the site you are applying the template to has been created for the base team site template.
- Deleted
Pieter is right it seems your site collection is not created yet. did you add code to provision the site collection?
Thank you Deleted and Pieter Veenstra.
Yes, in the past I already succesfully created site collections using the SharePoint UI or Office Dev PnP New-SPOTenantSite command, before I provisioned the site templates using the Apply-SPOProvisioningTemplate. The Apply-SPOProvisioningTemplate reference an XML-file with the configuration located in a <pnp:ProvisioningTemplate> element. It seems this still is needed.
I'm still wondering: Why does the provisioning schema also includes elements regarding site collections, as described at https://github.com/OfficeDev/PnP-Provisioning-Schema/blob/master/ProvisioningSchema-2016-05.md#sitecollection?
<pnp:Provisioning>
<pnp:Sequence>
<pnp:SiteCollection>
... </pnp:SiteCollection>
</pnp:Sequence>
</pnp:Provisioning>