Lock and unlock sites
As a Global Administrator or SharePoint Administrator in Microsoft 365, you can block access to a site or make a site read-only by using Microsoft PowerShell to change the lock state of the site.
You can't set the lock state on the root site.
Change the lock state for a site
Follow these steps to change the lock state for a site by using PowerShell.
If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall "SharePoint Online Management Shell."
Connect to SharePoint as a Global Administrator or SharePoint Administrator in Microsoft 365. To learn how, see Getting started with SharePoint Online Management Shell.
At the PowerShell command prompt, type the following command, and then press ENTER.
Set-SPOSite -Identity "<SiteURL>" -LockState "<State>"
Where: SiteURL is the URL of the site that you want to lock or unlock and State is one of the following values:
Unlock to unlock the site and make it available to users.
ReadOnly to prevent users from adding, updating, or deleting content. A message will appear on the site stating that the site is under maintenance and is read-only.
NoAccess to prevent users from accessing the site and its content. If you've provided a NoAccessRedirectUrl value for your organization (below), traffic will be redirected to the URL you specified. If you haven't set this URL, a 403 error will be displayed.
If the site was closed and made read-only through a site closure policy, the PowerShell command to unlock the site will not work.
Set-SPOTenant -NoAccessRedirectUrl 'https://www.contoso.com'