Share via

Add-PnPJavaScriptLink will raise the following error "Access denied. You do not have permission to perform this action or access this resource."

john john 1,031 Reputation points
2020-11-27T13:49:30.86+00:00

I run the following PnP script using the office 365 global admin, to inject a javascript file to our modern communication site:-

PS C:\WINDOWS\system32> Connect-PnPOnline "https://****.com/sites/DocumentProcess/" -UseWebLogin

PS C:\WINDOWS\system32>  Add-PnPJavaScriptLink -Name HomeLink -Url "https:/****.com/sites/DocumentApproval/SiteAssets/approvalprocess.js" -Scope Site
Add-PnPJavaScriptLink : Access denied. You do not have permission to perform this action or access this resource.
At line:1 char:2
+  Add-PnPJavaScriptLink -Name HomeLink -Url "https://***.sha ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-PnPJavaScriptLink], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Branding.AddJavaScriptLink

but i got this error as shown above "Access denied. You do not have permission to perform this action or access this resource."? any advice?

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Allen Xu_MSFT 13,896 Reputation points
    2020-11-30T07:00:57.887+00:00

    Hi @john john ,

    I could reproduce this issue on a modern site, however it could run successfully on a classic site.

    As said in the following article, “Add-PnPJavaScriptLink” is valid only for SharePoint classic site experience.
    https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/add-pnpjavascriptlink?view=sharepoint-ps

    Since the site you applied the script to is a modern site, It cannot be successfully executed. You can have a try on a classic site.

    I hope this information has been useful, please let me know if you still need assistance.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.