Skip to content

invoke-pnpsitetemplate‎: can't apply existing template to new site #1214

@GiHubNewbie

Description

@GiHubNewbie

Hello,

I am trying to apply a template to a new modern SharePoint site (without M365 group) and no matter the method I use (physical template file, memory stream, etc.), I always end up having the same issue which is:
‘The content type of the response is text/plain; charset=utf-8. Status code: NotFound.’
I am using PnP.PowerShell 3.1.0.

Here is the code I am trying:

Here is the actual code I tried running ( I would however prefer to place the template in a memory stream rather than having to create a physical file.)

#Connect-PnPOnline -Url $adminUrl -Tenant $tenantId -ClientId $clientId -Thumbprint $thumbprint

-----------------------------

Check if target site already exists

-----------------------------

$existingSite = Get-PnPTenantSite | Where-Object { $_.Url -eq $newSiteUrl }

if (-not $existingSite) {
Write-Host "Creating new site: $targetSite"
New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title $newSite
-Url $newSiteUrl -Owner $newSiteOwner
-Lcid 1033
# Optional: wait a few seconds for provisioning to complete
Start-Sleep -Seconds 30
} else {
Write-Host "Target site already exists: $newSiteUrl"
}

if (-not (Get-Command Get-PnPSiteTemplate -ErrorAction SilentlyContinue)) {
Write-Error "Get-PnPSiteTemplate / Invoke-PnPSiteTemplate not available. Install/Import PnP.PowerShell."
exit 1
}

---------------------------------------------------

Step 1: Connect to the source site

---------------------------------------------------

Connect-PnPOnline -Url $sourceSiteUrl -Tenant $tenantId -ClientId $clientId -Thumbprint $thumbprint

---------------------------------------------------

Step 2: Get the template in memory

---------------------------------------------------

Get-PnPSiteTemplate -Out ".\template.xml"

---------------------------------------------------

Step 3: Connect to the target site

---------------------------------------------------

Connect-PnPOnline -Url $newSiteUrl -Tenant $tenantId -ClientId $clientId -Thumbprint $thumbprint

---------------------------------------------------

Step 4: Apply the template directly from memory

---------------------------------------------------

Invoke-PnPSiteTemplate -Path ".\template.xml" -ClearNavigation #fileInputInstance $template -ClearNavigation:$false -Handlers All

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions