I'm crafting PNP Provisioning XML templates for use on team sites and storing them into a SharePoint document library for use in PowerShell scripts.

Each time I run the Apply-pnpprovisioningtemplate command I'm getting the following error.

Apply-PnPProvisioningTemplate : File not found
At line:1 char:1
+ Apply-PnPProvisioningTemplate -Path $xmllistitems.FieldValues.FileRef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Apply-PnPProvisioningTemplate], FileNotFoundException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Site.ApplyProvisioningTemplate

The code I'm using is as follows:

$Password=Get-content "[MY Password Path]\SecurePW\ckcpw.txt"|ConvertTo-SecureString
$userCredential=New-Object system.management.automation.pscredential($mysources.AdminUPN,$Password)
$adminSiteUrl = "https://"+$mysources.Org+"-admin.sharepoint.com"
Connect-SPOService $adminSiteUrl -Credential $userCredential

#Connect-PnPOnline -url ($MySources.sourceurl) -Credentials $userCredential 

connect-pnponline -url "https://[tenant]/sites/CKCShareptDev" -Credentials $usercredential

$XMLList=get-pnplist "xmltemplatebak"
$xmllistitems=get-pnplistitem -list $xmllist -id 3 -fields "FileRef", "File_x0020_Type","FileLeafRef"

foreach($Item in $xmllistitems){

    #Write-Host $Item['FileRef'] + " " + $Item['File_x0002_Type']+ " " + $Item['FileLeafRef']

    Connect-PnPOnline -url "https://[tenant].sharepoint.com/sites/ProvTest" -Credentials $usercredential
    Apply-PnPProvisioningTemplate -Path $item['FileRef']     }

Can't figure out how to access the file to use in the Apply-PNPProvisioningTemplate command.

Thanks for the assistance.


You can directly pass the specific template file reference like below from the document library :

Apply-PnPProvisioningTemplate -Path https://tenant.sharepoint.com/sites/templatestorage/Documents/template.pnp


From your existing code, download the PnP template file from the document library to a temp folder, then refer the PnP template file from the temp folder location like below :

Apply-PnPProvisioningTemplate -Path "C:\temp\template.xml" 

Then after applying the PnP template from temp folder, delete the template file.

Note :

Download and deletion can be handled through the PowerShell code in the same apply-pnpprovisioningtemplate script only.

For various other ways of referring PnP template refer to the below MSDN article :


| improve this answer | |
  • The first solution didn't work (or I was doing it wrong). The template is located in a document lib as follows: tenant/sites/CKCShareptDev/XMLTemplateBak/ so by your example the url to use in the apply should be tenant/sites/ckcshareptdev/xmltemplatebak/template.xml This failed...was trying to avoid downloading the file but I think I may have to. – Pablo Apr 26 at 20:22

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.