SOLVED

PnP PowerShell error: Apply-PnPProvisioningTemplate : File Not Found

%3CLINGO-SUB%20id%3D%22lingo-sub-272096%22%20slang%3D%22en-US%22%3EPnP%20PowerShell%20error%3A%20Apply-PnPProvisioningTemplate%20%3A%20File%20Not%20Found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-272096%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%20I'm%20trying%20to%20run%20the%20below%20script%20on%20my%20tenant%20just%20to%20get%20started%20with%20building%20a%20more%20complex%20provisioning%20template%3A%3C%2FP%3E%3CPRE%3E%24templateSiteUrl%20%3D%20%22https%3A%2F%2FMYTENANT.sharepoint.com%2Fsites%2Fpstemplate1%22%3CBR%20%2F%3E%24templatePath%20%3D%20%22C%3A%5Ctemp%5CprovTemplate1.pnp%22%3CBR%20%2F%3E%24title%20%3D%20%22TestC%22%3CBR%20%2F%3E%24url%20%3D%20%22testC%22%3CBR%20%2F%3E%24description%20%3D%20%22test%22%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(%24creds%20-eq%20%24null)%20%7B%3CBR%20%2F%3E%20%24creds%20%3D%20Get-Credential%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EConnect-PnPOnline%20https%3A%2F%2FMYTENANT-admin.sharepoint.com%20-Credentials%20%24creds%3CBR%20%2F%3ENew-PnPSite%20-Type%20CommunicationSite%20-Title%20%22Project%20Site%20Template%22%20-Url%20%24templateSiteUrl%20-Description%20%22Template%20test%22%20-SiteDesign%20Blank%3CBR%20%2F%3ENew-PnPSite%20-Type%20CommunicationSite%20-Title%20%24title%20-Url%20%22https%3A%2F%2FMYTENANT.sharepoint.com%2Fsites%2F%24url%22%20-Description%20%24description%20-SiteDesign%20Blank%3CBR%20%2F%3EDisconnect-PnPOnline%3CBR%20%2F%3E%3CBR%20%2F%3EConnect-PnPOnline%20%24templateSiteUrl%20-Credentials%20%24creds%3CBR%20%2F%3EGet-PnPProvisioningTemplate%20-Out%20%24templatePath%20-Force%3CBR%20%2F%3EDisconnect-PnPOnline%3CBR%20%2F%3E%3CBR%20%2F%3EConnect-PnPOnline%20https%3A%2F%2FMYTENANT.sharepoint.com%2Fsites%2F%24url%20-Credentials%20%24creds%3CBR%20%2F%3EApply-PnPProvisioningTemplate%20-Path%20%24templatePath%20-ClearNavigation%3CBR%20%2F%3EDisconnect-PnPOnline%3C%2FPRE%3E%3CP%3ESeems%20a%20simple%20enough%20script.%20Build%20two%20simple%20Communication%20sites%2C%20then%20build%20a%20template%20from%20one%20and%20apply%20to%20the%20other.%20Theoretically%2C%20nothing%20should%20actually%20change%20in%20the%20second%20site.%3C%2FP%3E%3CP%3EHowever%2C%20when%20I%20run%20this%2C%20I%20get%20this%20error%20in%20the%20output%3A%3C%2FP%3E%3CPRE%3Ehttps%3A%2F%2FMYTENANT.sharepoint.com%2Fsites%2Fpstemplate1%3CBR%20%2F%3Ehttps%3A%2F%2F%3CSPAN%3EMYTENANT%3C%2FSPAN%3E.sharepoint.com%2Fsites%2FtestC%3CBR%20%2F%3EWARNING%3A%20ListInstance%20Style%20Library%20is%20a%20Style%20Library%20of%20a%20site%20with%20NoScript%20enabled%20and%20will%20be%20skipped%3CBR%20%2F%3E%3CSTRONG%3EApply-PnPProvisioningTemplate%20%3A%20File%20Not%20Found.%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EAt%20line%3A21%20char%3A1%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20Apply-PnPProvisioningTemplate%20-Path%20%24templatePath%20-ClearNavigation%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20%2B%20CategoryInfo%20%3A%20WriteError%3A%20(%3A)%20%5BApply-PnPProvisioningTemplate%5D%2C%20ServerException%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20%2B%20FullyQualifiedErrorId%20%3A%20EXCEPTION%2CSharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate%3C%2FSTRONG%3E%3C%2FPRE%3E%3CP%3EAny%20thoughts%3F%20If%20you%20run%20my%20script%20above%2C%20do%20you%20get%20the%20same%20error%3F%20Thanks%20in%20advance%20for%20the%20help...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-274610%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20PowerShell%20error%3A%20Apply-PnPProvisioningTemplate%20%3A%20File%20Not%20Found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-274610%22%20slang%3D%22en-US%22%3E%3CP%3ERemoving%20those%20lines%20did%20in%20fact%20fix%20the%20issue.%20My%20script%20isn't%20ready%2C%20though%2C%20because%20the%20PowerShell%20I%20wrote%20to%20automatically%20change%20the%20contents%20of%20the%20PNP%20file%20isn't%20working.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20now%2C%20the%20solution%20to%20the%20issue%20reported%20in%20the%20OP%20is%20to%20remove%20the%20%3CFIELD%3E%20elements%20where%20ID%20%3D%26nbsp%3B1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be.%3C%2FFIELD%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20remove%20those%20elements%20by%20hand%2C%20the%20template%20works.%20Now%20I%20need%20to%20get%20my%20script%20to%20automatically%20fix%20the%20template%20working%2C%20but%20that's%20a%20topic%20for%20another%20thread.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-274469%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20PowerShell%20error%3A%20Apply-PnPProvisioningTemplate%20%3A%20File%20Not%20Found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-274469%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20running%20as%20admin%2C%20and%20the%20script%20is%20just%20typed%20into%20the%20ISE%20right%20now%2C%20I%20haven't%20saved%20it.%20I%20don't%20think%20that%20would%20be%20a%20factor%2C%20though%2C%20since%20I've%20typed%20the%20full%20path%20to%20the%20template%20into%20the%20-Out%2F-Path%20parameters.%3C%2FP%3E%3CP%3EHowever%2C%20I%20have%20made%20one%20new%20discovery...%20Just%20discovered%20the%20%22-debug%22%20switch%20on%20the%20Apply%20cmdlet%2C%20which%20pauses%20the%20script%20when%20an%20error%20occurs.%20In%20conjunction%20with%20the%20nice%20status%20bar%2C%20this%20showed%20me%20that%20the%20part%20of%20the%20template%20that's%20causing%20the%20issue%20is%3A%3C%2FP%3E%3CPRE%3E%3CSPAN%3E%26lt%3B%3C%2FSPAN%3E%3CSPAN%3Epnp%3AFields%3C%2FSPAN%3E%3CSPAN%3E%26gt%3B%3C%2FSPAN%3E%0A%3CSPAN%3E%26lt%3B%3C%2FSPAN%3E%3CSPAN%3EField%3C%2FSPAN%3E%20%3CSPAN%3EID%3C%2FSPAN%3E%3CSPAN%3E%3D%22%7B1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be%7D%22%3C%2FSPAN%3E%20%3CSPAN%3EName%3C%2FSPAN%3E%3CSPAN%3E%3D%22_DisplayName%22%3C%2FSPAN%3E%20%3CSPAN%3EDisplaceOnUpgrade%3C%2FSPAN%3E%3CSPAN%3E%3D%22TRUE%22%3C%2FSPAN%3E%20%3CSPAN%3ESortable%3C%2FSPAN%3E%3CSPAN%3E%3D%22FALSE%22%3C%2FSPAN%3E%20%3CSPAN%3EFilterable%3C%2FSPAN%3E%3CSPAN%3E%3D%22FALSE%22%3C%2FSPAN%3E%20%3CSPAN%3EHidden%3C%2FSPAN%3E%3CSPAN%3E%3D%22FALSE%22%3C%2FSPAN%3E%20%3CSPAN%3EReadOnly%3C%2FSPAN%3E%3CSPAN%3E%3D%22TRUE%22%3C%2FSPAN%3E%20%3CSPAN%3EShowInFileDlg%3C%2FSPAN%3E%3CSPAN%3E%3D%22FALSE%22%3C%2FSPAN%3E%20%3CSPAN%3EType%3C%2FSPAN%3E%3CSPAN%3E%3D%22Lookup%22%3C%2FSPAN%3E%20%3CSPAN%3EDisplayName%3C%2FSPAN%3E%3CSPAN%3E%3D%22Sensitivity%22%3C%2FSPAN%3E%20%3CSPAN%3EList%3C%2FSPAN%3E%3CSPAN%3E%3D%22Docs%22%3C%2FSPAN%3E%20%3CSPAN%3EListInternal%3C%2FSPAN%3E%3CSPAN%3E%3D%22IpLabelCache%22%3C%2FSPAN%3E%20%3CSPAN%3EFieldRef%3C%2FSPAN%3E%3CSPAN%3E%3D%22LabelId%22%3C%2FSPAN%3E%20%3CSPAN%3EShowField%3C%2FSPAN%3E%3CSPAN%3E%3D%22DisplayName%22%3C%2FSPAN%3E%20%3CSPAN%3ELeftList%3C%2FSPAN%3E%3CSPAN%3E%3D%22Docs%22%3C%2FSPAN%3E%20%3CSPAN%3ELeftColumnName%3C%2FSPAN%3E%3CSPAN%3E%3D%22IpLabelId%22%3C%2FSPAN%3E%20%3CSPAN%3EJoinColName%3C%2FSPAN%3E%3CSPAN%3E%3D%22LabelId%22%3C%2FSPAN%3E%20%3CSPAN%3EJoinRowOrdinal%3C%2FSPAN%3E%3CSPAN%3E%3D%220%22%3C%2FSPAN%3E%20%3CSPAN%3EJoinType%3C%2FSPAN%3E%3CSPAN%3E%3D%22LEFT%20OUTER%22%3C%2FSPAN%3E%20%3CSPAN%3ESchemaVersion%3C%2FSPAN%3E%3CSPAN%3E%3D%2216.0.162.0%22%3C%2FSPAN%3E%20%3CSPAN%3ERecreateIfMissing%3C%2FSPAN%3E%3CSPAN%3E%3D%22TRUE%22%3C%2FSPAN%3E%20%3CSPAN%3ESourceID%3C%2FSPAN%3E%3CSPAN%3E%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fsharepoint%2Fv3%22%3C%2FSPAN%3E%20%3CSPAN%3EStaticName%3C%2FSPAN%3E%3CSPAN%3E%3D%22_DisplayName%22%3C%2FSPAN%3E%20%3CSPAN%3EFromBaseType%3C%2FSPAN%3E%3CSPAN%3E%3D%22TRUE%22%3C%2FSPAN%3E%20%3CSPAN%3E%2F%26gt%3B%3C%2FSPAN%3E%0A%3CSPAN%3E%3CSPAN%3Epnp%3AFields%3C%2FSPAN%3E%3CSPAN%3E%26gt%3B%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EI'm%20going%20to%20try%20removing%20that%20from%20the%20XML%20file%20manually%2C%20but%20if%20that%20works%20that's%20only%20a%20partial%20solution.%20I'm%20writing%20a%20script%20that%20a%20client%20can%20%22fire%20and%20forget%2C%22%20so%20everything%20needs%20to%20be%20done%20in%20the%20script%2C%20ultimately.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-274320%22%20slang%3D%22en-US%22%3ERe%3A%20PnP%20PowerShell%20error%3A%20Apply-PnPProvisioningTemplate%20%3A%20File%20Not%20Found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-274320%22%20slang%3D%22en-US%22%3E%3CP%3ECould%20it%20be%20that%20the%20file%20is%20in%20another%20directory%20then%20the%20one%20you%20are%20running%20your%20script%20from%3F%20and%20do%20you%20run%20it%20under%20Admin%20credentials%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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 = "https://MYTENANT.sharepoint.com/sites/pstemplate1"
$templatePath = "C:\temp\provTemplate1.pnp"
$title = "TestC"
$url = "testC"
$description = "test"

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

Connect-PnPOnline https://MYTENANT-admin.sharepoint.com -Credentials $creds
New-PnPSite -Type CommunicationSite -Title "Project Site Template" -Url $templateSiteUrl -Description "Template test" -SiteDesign Blank
New-PnPSite -Type CommunicationSite -Title $title -Url "https://MYTENANT.sharepoint.com/sites/$url" -Description $description -SiteDesign Blank
Disconnect-PnPOnline

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

Connect-PnPOnline https://MYTENANT.sharepoint.com/sites/$url -Credentials $creds
Apply-PnPProvisioningTemplate -Path $templatePath -ClearNavigation
Disconnect-PnPOnline

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:

https://MYTENANT.sharepoint.com/sites/pstemplate1
https://MYTENANT.sharepoint.com/sites/testC
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
Highlighted

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?

Highlighted

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:

<pnp:Fields>
<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="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />
</pnp:Fields>

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.

Highlighted
Best Response confirmed by Brandon Murray (Occasional Contributor)
Solution

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.