SOLVED

Home.aspx content and webparts when extracting PnP site provisioning schema?

Copper Contributor

Should I be able to get the page content of the site welcome page (e.g. /SitePages/Home.aspx) and its webparts using Get-SPOProvisioningTemplate (PowerShell) or GetProvisioningTemplate (C#)? I would think welcome page content and webpart extraction this is included in the core implementation as that is normally needed when extracting site schema.

 

How do I extract the SitePages/Home.aspx content with webparts? Do I need to implement an extensibility provider?

13 Replies

Hi @Pasi Bergman,

 

The Get-SPOProvisioingTemplate cmdlet collects the welcome page including web parts.

 

I'm assuming that you are extracting the template as a .pnp file. If you extract it as an .xml it will be easier to check if your page/web parts are included. Of course it is better to use the .pnp format for normal use but for debug purposes it can help to use the .xml format.

Be aware that if you put webparts on the homepage which contain documents/lists that the view is not automaticly the same. 

check my blog about views:

http://www.sharepoint-specialist.nu/unable-change-view-list-view-web-part-csom-solution-office365/

 

Hi @Pieter Veenstra 

 

Thank you for taking the time to reply. I really appreciate it.

 

I am expecting the Get-SPOProvisioingTemplate to collect also the Home.aspx but the XML file I'm getting does not include Pages element and threfore no page content nor webpart either.

 

This is what I do...

1) I create a new SharePoint Online Team Site (English) with my account as the site collection administrator

2) I then edit the welcome page /SitePages/Home.aspx. I remove the default content except for the Documents webpart. I also add some text to the wikifield content area and then I save the page.

3) Using the latest PnP SharePoint Online PowerShell I then

 

Connect-SPOnline -Url https://mytenant.sharepoint.com/sites/mytemplatesite -UseWebLogin
Get-SPOProvisioningTemplate -Out .\mytemplatesite1.xml 

 

6) I also try

Get-SPOProvisioningTemplate -Out .\mytemplatesite2.xml -PersistPublishingFiles

and

Get-SPOProvisioningTemplate -Out .\mytemplatesite3.xml -IncludeNativePublishingFiles

None of these prorduce xml file with the Pages element and content of the Home.aspx (i.e. WebPart and WikiField contents).

 

I won't attach the schema xml's. Hopefully everyone takes my word for it that the Pages there is no Pages nor Page element in those. I'm attaching the TRACE LOGs of the three Get-SPOProvisioningTemplate executions numbered as 1, 2 and 3.

Hi @Deleted

 

Great blog post! Thank you for sharing it. Your post will certainly help after my initial problem has been resolved.

When you export as .xml files the aspx page itself will not be exported.
You can simple put an .aspx file in the same folder as the .xml manually before you import it. A simple one off export of the page with share point designer will do. You can then use this apsx file for any future pages.
If you use .pnp rather than .xml then all will work fine.
Did you check you .xml files? If you search for webpart do you find anything in the xml?

Hi @Pieter Veenstra

 

Thanks again for contributing. This issue is quite annoying and any help is appreciated.

 

As I mentioned, the extracted provisioning template (xml) does not contain Pages element nor Page element. Below is the result of the initial schema extraction

Get-SPOProvisioningTemplate -Out .\mytemplatesite1.xml 

I have removed the content of the AdditionalAdministrators, SiteFields and ContentTypes, but I have not touched anything else.

 

<?xml version="1.0"?>
<pnp: Provisioning xmlns: pnp="http://schemas.dev.office.com/PnP/2016/05/ProvisioningSchema">
  <pnp: Preferences Generator="OfficeDevPnP.Core, Version=2.8.1610.1, Culture=neutral, PublicKeyToken=3751622786b357c2" />
  <pnp: Templates ID="CONTAINER-TEMPLATE-2912D0BE8A6047548043990D05268BC2">
    <pnp: ProvisioningTemplate ID="TEMPLATE-2912D0BE8A6047548043990D05268BC2" Version="1" BaseSiteTemplate="STS#0">
      <pnp: WebSettings RequestAccessEmail="someone@example.com" NoCrawl="false" WelcomePage="SitePages/Home.aspx" SiteLogo="" AlternateCSS="" MasterPageUrl="{masterpagecatalog}/seattle.master" CustomMasterPageUrl="{masterpagecatalog}/seattle.master" />
      <pnp: RegionalSettings AdjustHijriDays="0" AlternateCalendarType="None" CalendarType="Gregorian" Collation="25" FirstDayOfWeek="Sunday" FirstWeekOfYear="0" LocaleId="1033" ShowWeeks="false" Time24="false" TimeZone="13" WorkDayEndHour="5:00PM" WorkDays="62" WorkDayStartHour="8:00AM" />
      <pnp: SupportedUILanguages>
        <pnp: SupportedUILanguage LCID="1033" />
      </pnp: SupportedUILanguages>
      <pnp: AuditSettings AuditLogTrimmingRetention="90" TrimAuditLog="true">
        <pnp: Audit AuditFlag="None" />
      </pnp: AuditSettings>
      <pnp: Security>
        <pnp: AdditionalAdministrators>
        </pnp: AdditionalAdministrators>
        <pnp: Permissions />
      </pnp: Security>
      <pnp: SiteFields>
      </pnp: SiteFields>
      <pnp: ContentTypes>
      </pnp: ContentTypes>
      <pnp: Features>
        <pnp: WebFeatures>
          <pnp: Feature ID="b77b6484-364e-4356-8c72-1bb55b81c6b3" />
        </pnp: WebFeatures>
      </pnp: Features>
    </pnp: ProvisioningTemplate>
  </pnp: Templates>
</pnp: Provisioning>

 

Edit: I added spaces after each pnp: to remove the emojis from my reply.

 

Hi @Pasi Bergman,

 

I just tried creation a new site collection using the team site template. Then I exported it and I'm getting a lot more back.

 

for examples my sitefields look like this:

 

< pnp: SiteFields>
<Field ID="{e954460e-4ac3-463a-a9c4-bf9e55564e24}" Type="DateTime" DisplayName="Last Shared By Time" Name="LastSharedByTime" StaticName="LastSharedByTime" Group="_Hidden" Sealed="TRUE" AllowDeletion="FALSE" ReadOnly="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" ShowInListSettings="FALSE" Viewable="FALSE" SourceID="{808997ce-c646-44e1-aa26-8b96b3fa034c}" />
<Field ID="{ef991a83-108d-4407-8ee5-ccc0c3d836b9}" Type="UserMulti" DisplayName="Shared With" Mult="TRUE" Name="SharedWithUsers" StaticName="SharedWithUsers" Group="_Hidden" Sealed="TRUE" AllowDeletion="FALSE" ReadOnly="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" ShowInListSettings="FALSE" Viewable="FALSE" SourceID="{808997ce-c646-44e1-aa26-8b96b3fa034c}" />
<Field ID="{725e8dc4-ee43-488a-94fa-85a380aa1302}" Type="Note" DisplayName="Last Shared By User" Name="LastSharedByUser" StaticName="LastSharedByUser" Group="_Hidden" Sealed="TRUE" AllowDeletion="FALSE" ReadOnly="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" ShowInListSettings="FALSE" Viewable="FALSE" SourceID="{808997ce-c646-44e1-aa26-8b96b3fa034c}" />
<Field ID="{d3c9caf7-044c-4c71-ae64-092981e54b33}" Type="Note" DisplayName="Shared With Details" Name="SharedWithDetails" StaticName="SharedWithDetails" Group="_Hidden" Sealed="TRUE" AllowDeletion="FALSE" ReadOnly="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" ShowInListSettings="FALSE" Viewable="FALSE" SourceID="{808997ce-c646-44e1-aa26-8b96b3fa034c}" />
</ pnp: SiteFields>

 

It almost looks like you haven't got the rigth permissions or something else is going wrong. 

 

I looked at your connect-sponline command:

 

 

Connect-SPOnline -Url https://mytenant.sharepoint.com/sites/mytemplatesite -UseWebLogin
 

Can you try without the -UseWebLogin

 

and use something like this:

 

 

$url = "https://mytenant.sharepoint.com/sites/testteam"
$username = "admin@mytenant.onmicrosoft.com"
  
if ($credentials -eq $null)
{
$credentials = Get-Credential -Message "Please supply password" -UserName $username
Connect-SPOnline $url -Credentials $credentials
}
 

 

 

Hi Patri,

 

i added my script which i default use hope it helps it has some overhead but it will give you the info you need.

   Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking 
        Get-Command -Module *PnP*
$User = "adm.XXX@XXX.onmicrosoft.com"
$Site = "https://XXXX.sharepoint.com/sites/XXX"
$tennant="https://XXX-admin.sharepoint.com/"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString


$Context = New-Object Microsoft.SharePoint.Client.ClientContext($tennant)

$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds
Connect-SPOnline -Url $Site -Credential $cred
Write-Output "Context obtained";
Get-SPOProvisioningTemplate   -Force -Out C:\temp\Workflow.xml 

And please make sure you use the latest Powershell command for SharePoint online 

Hi @Pieter Veenstra

 

Great suggestion. This issue is somehow related to the login method.

 

I execute the following PowerShell lines. Note! The SharePointPnPPowerShellOnline\ is there because of same names of the diefferent SharePointPnPPowerShell* modules have same cmdlet's with the same name ('clobber').

 

 

$site   = "https://mytenant.sharepoint.com/sites/pasi-test-template"

SharePointPnPPowerShellOnline\Set-SPOTraceLog -On -Level Debug -LogFile .\mytemplate-creds.log
# # Log in using network credentials - requires <tenant>.onmicrosoft.com account
#
$Creds = Get-Credential SharePointPnPPowerShellOnline\Connect-SPOnline -Url $site -Credential $Creds SharePointPnPPowerShellOnline\Get-SPOProvisioningTemplate -Force -Out .\mytemplate-creds.xml SharePointPnPPowerShellOnline\Set-SPOTraceLog -Off SharePointPnPPowerShellOnline\Set-SPOTraceLog -On -Level Debug -LogFile .\mytemplate-weblogin.log #
# Log in using Web Login - you can use any valid accout
# SharePointPnPPowerShellOnline\Connect-SPOnline -Url $site -UseWebLogin SharePointPnPPowerShellOnline\Get-SPOProvisioningTemplate -Force -Out .\mytemplate-weblogin.xml SharePointPnPPowerShellOnline\Set-SPOTraceLog -Off

 

The result:

- Using the -Credential produces the xml WITH the page content. 

- Using the -UseWebLogin produces the xml WITHOUT the page content.

 

I'm using only one and same credential in both cases. Result XML file is different.

I'm attaching the trace logs of both runs. The logs show that in -Credential case the Pages is handled (don't worry about the webpart warnings). In -UseWebLogin the Pages is not handled.

Same issue/feature exists in SharePointPnPPowerShell2013

 

$creds = Get-Credential
Connect-SPOnline -Url https://youronprem/sites/template -Credential $creds
Get-SPOProvisioningTemplate -Out .\onprem-template-creds.xml

Connect-SPOnline -Url https://youronprem/sites/template -CurrentCredentials
Get-SPOProvisioningTemplate -Out .\onprem-template-currentcreds.xml

Using -Credential produces XML schema WITH the page content and webparts

Using -CurrentCredentials produces XML schema WITHOUT the page content and webparts.

 

 

best response confirmed by Pasi Bergman (Copper Contributor)
Solution

A little update from the PnP Core Team: I just changed the behaviour of the PageContents handler (which is the handler that extracts the homepage). It was checking for the presence of Credentials on the ClientContext and if not present it would not execute the extraction of artifacts. That check is still valid for On-Premises, due to the fact that we have to call a webservice to work around CSOM limitations, but is not needed anymore for SPO as that version of CSOM allows us to export all webparts. I now made that check conditional based upon the version of the NuGet package you're running, and it will be available in version 2.12.1702.0 (the February 2017 release).

I have the same issue and can only connect to sitecollections by the parameter -UseWeblogin because we are using ADFS and WMA. Please fix this or give me some workaround.

1 best response

Accepted Solutions
best response confirmed by Pasi Bergman (Copper Contributor)
Solution

A little update from the PnP Core Team: I just changed the behaviour of the PageContents handler (which is the handler that extracts the homepage). It was checking for the presence of Credentials on the ClientContext and if not present it would not execute the extraction of artifacts. That check is still valid for On-Premises, due to the fact that we have to call a webservice to work around CSOM limitations, but is not needed anymore for SPO as that version of CSOM allows us to export all webparts. I now made that check conditional based upon the version of the NuGet package you're running, and it will be available in version 2.12.1702.0 (the February 2017 release).

View solution in original post