I am creating a PnP PowerShell script to set up sites automatically in SharePoint Online. The final part of it is about deploying document templates to the content types that we are using. Having the document templates available from the +New menu of the document library would be a major improvement to productivity for everyone in the company. The content types are also available in document sets.
However, when I use Add-PnPFile to copy my templates to the content type folders in _cts I get
Add-PnPFile : Access denied.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPFile], ServerUnauthorizedAccessException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Files.AddFile
Copying to a regular document library with Add-PnPFile works. Also I can add the templates manually to the content types, using the UI.
I am not allowed to do anything on the tenant level, I will only be site collection admin on the sites I set up. So if it is something on the tenant side that is preventing me, then I have to abandon the idea of having the templates connected to the content types. Then I need to find a work-around to get the templates to the document libraries.
What could be the problem and how can I solve it?
$filePath = "C:\Template\My Template.potx"
$MySpecialPresentationCT = "My Special Presentation"
#Works
#$SiteRelativePath = "/teams/my-testsite/Shared Documents"
#$SiteRelativePath = "Shared Documents"
#Access denied
#$SiteRelativePath = "_cts/$MySpecialPresentationCT"
$SiteRelativePath = "/teams/my-testsite/_cts/$MySpecialPresentationCT"
Add-PnPFile -Path $filePath -Folder $SiteRelativePath