Cannot change web part export mode to ‘All’, because custom scripting is disabled for site

Issue

The following error is encountered:

Processing site XX finished with warning: Cannot change web part export mode to ‘All’, because custom scripting is disabled for site: XX. Web part will be skipped (web part ID: XX, page: XX)

Cause

The sharepoint site denies changing the “web part export” mode, which Veeam requires to take a backup.

Resolution

Install the powershell sharepoint module

You only need to set this up once, after that it will be installed for future sessions

  1. Open PowerShell
  2. Install the SharePoint module
    Install-Module -Name Microsoft.Online.SharePoint.PowerShell
    

Remove the DenyAddAndCustomizePages restriction

  1. Connect to ms365 via Powershell by running
    Connect-SPOService -Url "<https://orgname-admin.sharepoint.com>"
    
  2. Once signed in run this command against the site reported in the error
    Set-SPOSite -Identity "<https://orgname.sharepoint.com/sites/sitename>" -DenyAddAndCustomizePages 0
    
  3. Close PowerShell
  4. Run the backup again and confirm the error is cleared

Further troubleshooting

If you see the error

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Then run the older Windows Powershell – the one with the blue icon, not the black icon