Upravit

Sdílet prostřednictvím


Lock and unlock sites

As a SharePoint Administrator and above 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.

Note

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.

  1. Download the latest SharePoint Online Management Shell.

    Note

    If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall "SharePoint Online Management Shell."

  2. Connect to SharePoint as a SharePoint Administrator and above in Microsoft 365. To learn how, see Getting started with SharePoint Online Management Shell.

  3. 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.

    Note

    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'
    

For more info about the LockState parameter, see Set-SPOSite. For more info about the NoAccessRedirectUrl parameter, see Set-SPOTenant.