0

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

1 Answer 1

0

Looks like someone raised this issue in 2020, but they didn't get it resolved: https://answers.microsoft.com/en-us/msoffice/forum/all/sharepoint-online-cts-folder/488dfdd8-34ec-409d-bdac-89560a60530d it's related to the modern sites only. Perhaps it's because the Scripting is not allowed in Modern sites by default.

Can you try enabling customizations on you sites using this example?

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com"
   
#Get Credentials to connect
$Cred = Get-Credential
   
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL
   
#sharepoint online enable custom scripts powershell - Disable DenyAddAndCustomizePages Flag
Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False
1
  • Unfortunately I do only have site collection admin rights, so I cannot even change this on my sites., unless the setting on the tenant allows this. I also tried Set-PnPSite -NoScriptSite $false without success. Since I have content types enabled I cannot use document library templates either, it is greyed out. But since I can do it using the UI, I guess I will have to figure out a way to automate it through the UI.
    – Gunilla
    Nov 16, 2021 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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