SharePoint Online lock / unlock your site

In some scenarios it is required to put a site in read only-mode, for example a project site, or to simply just remove access to it.

From the SharePoint Online Admin Center there is no way to lock your site, or to put it in read-only. There are two ways to achieve this, one is through PowerShell, the other one through the Site Settings of your Site Collection.


To remove the access to a site, use -LockState “NoAccess”. This will leave your site with a 403-error when you try to visit it afterwards.
To unlock a site, use -LockState “UnLock”.

EDIT: you can also put your site in read-only by using -LockState “ReadOnly”.

$siteUrl = “”
Connect-SPOService -Url $siteUrl

$site = “”
Set-SPOSite -Identity $site -LockState “NoAccess”

Or with the PnP module:

$site = “”
Connect-PnPOnline -url $site -UseWebLogin
Set-PnpSite -LockState NoAccess

Edit [4/24/2020]: It is not possible to lock a Group connected site or a OneDrive for Business site collection through PowerShell as it will throw an error back (403- error with the PnP-script or see hereunder for the first script) . However, you can still close a site via a site policy.

Set-SPOSite : URL is a Groups site collection. The valid parameters for this type of site collection are ‘-Identity’, ‘-AllowSelfServiceUpgrade’, ‘-DefaultLinkPermission’, ‘-DefaultSharingLinkType’, ‘-Den yAddAndCustomizePages’, ‘-DisableCompanyWideSharingLinks’, ‘-DisableSharingForNonOwners’, ‘-LockState’, ‘-Owner’, ‘-ResourceQuota’, ‘-ResourceQuotaWarningLevel’, ‘-SandboxedCodeActivationCapability’, ‘-SharingCapability’, ‘-ShowPeoplePickerSuggestionsForGue stUsers’, ‘-SocialBarOnSitePagesDisabled’, ‘-StorageQuota’, ‘-StorageQuotaReset’, and ‘-StorageQuotaWarningLevel’. At line:5 char:1 Set-SPOSite -Identity $site -LockState “NoAccess” ~~~~~~~~~~~~~ CategoryInfo : NotSpecified: (:) [Set-SPOSite], ServerException FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.SetSite

Site Collection Site Settings

Another way of locking your site is through the site settings of your Site Collection. For me this is the better way, since it leaves your site accessible for your users (remember the PowerShell option gives you a 403-error).

Navigate to the site settings and the Site Policies under “Site Collection Administration”.

Edit [4/24/2020]: If you do not see the “Site Policies” option, navigate to the “Site collection features” first and activate the “Site Policy” feature.

Create a new Site Policy, give it a name and make sure to select the option “The site collection will be read only when it is closed.”.

Now you need to attach this policy to your site. Navigate to Site Closure and Deletion option under “Site Administration”.

As you might notice, the “Close this site now” button is disabled. You first need to assign a policy to the site before it is enabled.

We can now close the site.

The result:

If you want to open the site again, navigate back to the Site Closure and Deletion option and click on the “Open this site” button.