SharePoint is managing default page template using Web Property Bag with name DefaultNewPageTemplateId
where it's storing Unique Id
of File
object of Site Page List Item.
You can set this property bag using any object model e.g. REST API, CSOM, PnP.PowerShell.
Below is the same for doing same using PnP.PowerShell
Connect-PnPOnline "https://contoso.sharepoint.com/sites/testcommunity" -Interactive
$page = Get-PnPPage -Identity "Templates/Page-Template-2.aspx" #Relative Page Template Url
$pageFile = $page.GetPageFile()
$web = Get-PnPWeb
Add-PnPPropertyBagValue -Key "DefaultNewPageTemplateId" -Value $pageFile.UniqueId -Web $web
If you receive error like (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Site might have NoScript enabled, this prevents setting some property bag values
. In this case you need enable scripting which you can set using SharePoint Online Management Shell. Below are the commands for the same:
Connect-SPOService -Url https://contoso-admin.sharepoint.com
Set-SPSite -Identity "https://contoso.sharepoint.com/sites/testcommunity" -DenyAddAndCustomizePages 0
Note: I couldn't find any official documentation for that but I am big fan of SharePoint Client Browser which helps me most of the time for this kind of scenario when I don't get anything from official Microsoft documentation :)