Knowledge Base

How to fix the ‘Access denied’ error when restoring backed up SharePoint data

Problem:

When restoring backed-up SharePoint sites by using CodeTwo Backup, you might receive the following or similar error:

Access denied. You do not have permission to perform this action or access this resource.

The error prevents the program from finishing the restore job successfully.

Solution:

This error is related to custom script settings, which determine whether users can customize SharePoint sites by running custom scripts. By default, this capability is blocked, preventing CodeTwo Backup from restoring the backed-up content.

To fix this error, you need to temporarily allow custom scripts in a site to which you are restoring your backed-up data. You can do so by changing the default settings in the SharePoint admin center or using SharePoint Online Management Shell.

Follow the links below to learn how to:

Warning

Before you enable custom scripts, you need to be aware of the security implications of doing so. See this Microsoft article to learn more.

Also, note that it is not possible to allow custom scripts in individual users’ OneDrive for Business locations.

Allowing custom scripts in the SharePoint admin center

  1. Sign in to the Microsoft 365 admin center using a global admin or SharePoint admin account.
  2. In the left menu, click Show all (if needed) and select SharePoint in the Admin centers section to switch to the SharePoint admin center (Fig. 1.).

Opening the SharePoint admin center.
Fig. 1. Opening the SharePoint admin center.

  1. In the SharePoint admin center, click Sites > Active sites in the left menu and select a relevant site from the list (Fig. 2.).

Accessing a site in the SharePoint admin center.
Fig. 2. Accessing active sites in the SharePoint admin center.

  1. In the pane that opens, switch to the Settings tab and click Edit in the Custom scripts section (Fig. 3.).

Editing custom script settings for a SharePoint site.
Fig. 3. Editing custom script settings for a SharePoint site.

  1. In the Custom scripts pane that opens, click Allowed and save your changes (Fig. 4.).

Allowing custom scripts in SharePoint site settings.
Fig. 4. Allowing custom scripts in SharePoint site settings.

  1. Next, you’ll be asked to confirm your choice again. Once you do so, custom scripts will be allowed in the selected SharePoint site.

Important

The use of custom scripts is automatically blocked again after 24 hours.

Allowing custom scripts by using SharePoint Online Management Shell

  1. Open the SharePoint Online Management Shell command prompt.
  2. Connect to your SharePoint Online by using the following command:
    Connect-SPOService -Url https://<organization>-admin.sharepoint.com -Credential <admincredential>
    where <organization> is the organization name set in Microsoft 365 (Office 365), and <admincredential> is the email address of your Microsoft 365 global admin or SharePoint admin. Enter the admin password when prompted.
  3. Run the following cmdlet:
    Set-SPOsite <siteURL> -DenyAddAndCustomizePages 0
    where <siteURL> is the URL of the specific SharePoint site. Once you do so, custom scripts will be allowed in the selected SharePoint site.

Important

The use of custom scripts is automatically blocked again after 24 hours.

Was this information useful?
Our Customers: