Forum Discussion

CheisCheis's avatar
CheisCheis
Copper Contributor
Oct 11, 2023

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:)

  • LeonPavesic's avatar
    LeonPavesic
    Silver 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:

    1. Open the SharePoint subsite.
    2. Click the Settings gear icon.
    3. Click Site permissions.
    4. Click Advanced permissions settings.
    5. In the Permission Levels section, click Contribute.
    6. In the Add Users or Groups section, enter the name of the SharePoint subsite owner and click Add.
    7. 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)

    • CheisCheis's avatar
      CheisCheis
      Copper 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:)

Resources