PnP PowerShell error: Apply-PnPProvisioningTemplate : File Not Found

Occasional Contributor

Hi all, I'm trying to run the below script on my tenant just to get started with building a more complex provisioning template:

$templateSiteUrl = ""
$templatePath = "C:\temp\provTemplate1.pnp"
$title = "TestC"
$url = "testC"
$description = "test"

if ($creds -eq $null) {
$creds = Get-Credential

Connect-PnPOnline -Credentials $creds
New-PnPSite -Type CommunicationSite -Title "Project Site Template" -Url $templateSiteUrl -Description "Template test" -SiteDesign Blank
New-PnPSite -Type CommunicationSite -Title $title -Url "$url" -Description $description -SiteDesign Blank

Connect-PnPOnline $templateSiteUrl -Credentials $creds
Get-PnPProvisioningTemplate -Out $templatePath -Force

Connect-PnPOnline$url -Credentials $creds
Apply-PnPProvisioningTemplate -Path $templatePath -ClearNavigation

Seems a simple enough script. Build two simple Communication sites, then build a template from one and apply to the other. Theoretically, nothing should actually change in the second site.

However, when I run this, I get this error in the output:
WARNING: ListInstance Style Library is a Style Library of a site with NoScript enabled and will be skipped
Apply-PnPProvisioningTemplate : File Not Found.
At line:21 char:1
+ Apply-PnPProvisioningTemplate -Path $templatePath -ClearNavigation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate

Any thoughts? If you run my script above, do you get the same error? Thanks in advance for the help...

3 Replies

Could it be that the file is in another directory then the one you are running your script from? and do you run it under Admin credentials?

I am running as admin, and the script is just typed into the ISE right now, I haven't saved it. I don't think that would be a factor, though, since I've typed the full path to the template into the -Out/-Path parameters.

However, I have made one new discovery... Just discovered the "-debug" switch on the Apply cmdlet, which pauses the script when an error occurs. In conjunction with the nice status bar, this showed me that the part of the template that's causing the issue is:

<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="Sensitivity" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="" RecreateIfMissing="TRUE" SourceID="" StaticName="_DisplayName" FromBaseType="TRUE" />

I'm going to try removing that from the XML file manually, but if that works that's only a partial solution. I'm writing a script that a client can "fire and forget," so everything needs to be done in the script, ultimately.

best response confirmed by Brandon Murray (Occasional Contributor)

Removing those lines did in fact fix the issue. My script isn't ready, though, because the PowerShell I wrote to automatically change the contents of the PNP file isn't working.


For now, the solution to the issue reported in the OP is to remove the <PNP:Field> elements where ID = 1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be.


When I remove those elements by hand, the template works. Now I need to get my script to automatically fix the template working, but that's a topic for another thread.