3

I try to export and import template using below PnP powershell scripts. There is no issue while exporting the template. But I get "Apply-PnPProvisioningTemplate : Input string was not in a correct format." message while applying template to target site collection. I couldn't find any error message in the log file. How can I solve this issue?

Export:

Connect-PnPOnline –Url https://tenant.sharepoint.com/sites/sourcesitecoll –Credentials (Get-Credential)
Get-PnPProvisioningTemplate -out template.pnp

Import:

Connect-PnPOnline –Url https://tenant.sharepoint.com/sites/targetsitecoll –Credentials (Get-Credential)
Set-PnPTraceLog -On -LogFile "C:\Works\PnP\logs.txt" -Level Debug
Apply-PnPProvisioningTemplate -Path "C:\Works\PnP\template.pnp"

Error message:

Apply-PnPProvisioningTemplate : Input string was not in a correct format. At line:1 char:1 + Apply-PnPProvisioningTemplate -Path "C:\Works\PnP\template.pnp ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], FormatException + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Site.ApplyProvisioningTemplate

SharePointPnPPowerShellOnline version is "3.10.1906.0"

1

This may not answer but you could try it as it's working in my environment.

Get:

#region Variables 
$Username = "user@tenant.onmicrosoft.com" 
$Password = "password" 
$siteURL = "https://tenant.sharepoint.com/sites/lee" 

#endregion Variables

#region Credentials 
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass) 
#endregion Credentials

Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials

$listName = "Site Assets";
$outputTemplateFileName = "C:\Lee\Script\template.xml";

$template = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists
$listTemplate = $template.Lists | Where-Object { $_.Title -eq $listName }
$template.Lists.Clear()
$template.Lists.Add($listTemplate)
Save-PnPProvisioningTemplate -InputInstance $template -Out $outputTemplateFileName

Apply:

#region Variables 
$Username = "user@tenant.onmicrosoft.com" 
$Password = "password" 
$siteURL = "https://tenant.sharepoint.com/sites/wiki" 

#endregion Variables

#region Credentials 
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass) 
#endregion Credentials

Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials

Apply-PnPProvisioningTemplate -Path "C:\Lee\Script\template.xml"
  • Hello Lee, first of all thank you quick reply and example. I have tried export and import root Pages library and it worked! But this way only allows to move specific list or library to another site collection. My aim is to move whole site collection to another one. Is there any way to do that as a workaround solution like your example? – Murat Jun 28 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.