Forum Discussion
Access denied to subsite using PowerShell
Hi,
when i run the Code 2 i have this error:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Code 1:
$url="Url_SubSite_in"
Connect-PnPOnline -Url $url -Interactive
Get-PnPSiteTemplate -Configuration "C:\Users\configu.json" -Out "C:\Users\template.xml"
Disconnect-PnPOnline
Code 2:
$url="Url_SubSite_out"
Connect-PnPOnline -Url $url -Interactive
Invoke-PnPSiteTemplate -Path "C:\Users\template.xml"
Disconnect-PnPOnline
I run both scripts using the credentials of the sharepoint subsite owner. This problem has never occurred when using sites and not subsites.
When i run the code i see that the error occur when powershell is trying to apply navigation things; i think the problem is about linkless headers (labels).
What should I do? There are some default settings that I have to change?
Thanks a lot to everyone:)
- LeonPavesicSilver Contributor
Hi CheisCheis,
the error message "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" means that the current user does not have the necessary permissions to perform the requested operation.
In the case of your PowerShell scripts, it is possible that the SharePoint subsite owner does not have the necessary permissions to apply navigation settings to the subsite. This could be because the subsite is a part of a larger site collection and the permissions are inherited from the site collection.
I believe that the best solution is to grant the SharePoint subsite owner the necessary permissions to apply navigation settings.
To do this, follow these steps:
- Open the SharePoint subsite.
- Click the Settings gear icon.
- Click Site permissions.
- Click Advanced permissions settings.
- In the Permission Levels section, click Contribute.
- In the Add Users or Groups section, enter the name of the SharePoint subsite owner and click Add.
- Click OK to save your changes.
Once you have granted the SharePoint subsite owner the necessary permissions, they should be able to run the PowerShell scripts without any problems.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)- CheisCheisCopper Contributor
Hi LeonPavesic,
unfortunately this method didn't work, this user is both the owner of the site and the subsite. Perhaps there are settings that need to be changed to enable this step. (These "settings" could be in Powershell, or in Sharepoint, or in the Microsoft 365 account, I don't know)
Thank you for your prompt reply:)