Get-PnPSiteScriptFromWeb : File Not Found

Introduction

When trying to create a site template out of the current team site in SharePoint Online, the PnP team has released a module Get-PnPSiteScriptFromWeb which gives the site definitions in JSON format which can be used to create a site template out of it.

When trying to connect to the SharePoint site using an admin connection and get the site script out of it ended up getting the below error.

SharePoint site

Fix

The issue here is it cannot get the script when not connected to the Site Context. To get the site script from the existing site, it is required to connect to the site first and then get the site script out of it.

# Connect to site to get the site script from it
$SiteUrl = ""

Connect-PnPOnline -Url $SiteUrl `
                  -ClientId "2345321-9655-4a5e-9342-124ewer5" `
                  -Tenant "cbcc2345-1564-419a-a16b-35812454578" `
                  -Thumbprint "45421212142a191990e4d311ThBptrndkgiri"

Get-PnPSiteScriptFromWeb -IncludeAll

Replace the $SiteUrl, ClientId, Tenant, and Thumbprint with respect to your organization setup. On successful completion, you should see something similar to the below screenshot.

ClientId

Please note that the PnP SharePoint PowerShell module deprecated the connecting to SharePoint online site using -Interactive and User Credentials. It is required to use the certificate to connect to the SharePoint online site using connect-pipeline modules. You can learn more about creating application registration in Entra and configuring the certificate to connect to SharePoint online sites from the references section.

References