Using the new PnP Provisioning Engine, you can model a site by configuring the design of Site Columns, Content Types, List Definitions and Instances, Composed Looks, Pages (either WebPart Pages or Wiki Pages), and much more, via your web browser. When you are done with the design, you can export what you have done into a persistent provisioning template format (XML, JSON, or whatever you like), and you can apply that template to as many target sites as you would like.
Reference Link: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/introducing-the-pnp-provisioning-engine
Before using the below code you need to run the command in powershell depending on the SharePoint Environment.
For SharePoint Online : Install-Module SharePointPnPPowerShellOnline
The others can be found on : https://github.com/SharePoint/PnP-PowerShell
Below is the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$title="Provision Template" $Export_Import = "Do you want to export Template XML or apply Template XML" $export = New-Object System.Management.Automation.Host.ChoiceDescription "&ExportXML", "Export XML" $apply = New-Object System.Management.Automation.Host.ChoiceDescription "&ApplyXML", "Apply Template" $options = [System.Management.Automation.Host.ChoiceDescription[]]($export, $apply) $result = $host.ui.PromptForChoice($title, $Export_Import, $options, 0) if($result -eq 0) { $Source_URL = Read-Host -Prompt 'Source URL' $User = Read-Host -Prompt 'Username' $Password = Read-Host -Prompt 'Password' -AsSecureString $TemplatePath = Read-Host -Prompt 'Template Path (e.g. F:\PnP-Provisioning-File.xml)' $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Password Connect-PnPOnline -Url $Source_URL -Credentials $credentials Get-PnPProvisioningTemplate -Out $TemplatePath Write-Host "Template Saved Successfully" -foregroundcolor green } else{ $Target_URL = Read-Host -Prompt 'Target URL' $User = Read-Host -Prompt 'Username' $Password = Read-Host -Prompt 'Password' -AsSecureString $TemplatePath = Read-Host -Prompt 'Template Path' $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$Password Connect-PnPOnline -Url $Target_URL -Credentials $credentials Apply-PnPProvisioningTemplate -Path $TemplatePath Write-Host "Template Applied Successfully" -foregroundcolor green } |
Some lines of code are redundant but it was intentionally kept that way, doesn’t me you need to do the same.