I am sure in the SharePoint world you would have run across a requirement of making the entire site collection(s) read only sometime. It is very easy if that requirement happens to be in SharePoint On-premise, we just go to the Central Admin and set the selected site collection as read only from under Locks and Quotas option.
SharePoint Online Problem
But what about SharePoint Online. When I searched for it, I came across this Lock/Unlock SharePoint Online Sites in Office 365 with PowerShell.
Unfortunately, contrary to the claim, this code doesn’t seem to have been tested with SharePoint Online as we can only use either NoAccess or Unlock Lockstates there. If you try to use other LockState mentioned in the script, you will be greeted with an error message.
But, we have to find a way around, so lets see – it’s a simple 2 step process:
Step 1: Create a new Site Policy
- Browse the site collection as a site collection admin and go to site settings.
- Click on “Site Policies” under Site Collection Administration
- It will open a new page to create a new site policy, click on “Create”
- It will open another page, asking for some information about the policy
- Type a name like “Make Read Only”, description, select the option “Do not close or delete site automatically” and check the option “The site collection will be read only when it is closed”
- After filling the details, click on OK
- You will be redirected back to a page which will show the created policy
- This completes first part of the configuration
Step 2: Associate the Site Policy with Site
- Now that we have a site policy in place, lets go ahead and use it. Go back to Site Settings and click on “Site Closure and Deletion” under Site Administration
- On the next page, you will see the site policy we created in previous step listed under a drop down for Site Policy. Close the site button would not be enabled currently.
- Select the “Make Read Only” site policy from the drop down and Click OK
- Open the page again by clicking “Site Closure and Deletion” link from under Site Administration
- This time you can see “Close this site now” button would be enabled
- Click on the button and and Whoa, you will get a message on top of the page mentioning “This site is read only at the site collection administrator’s request.”
- To remove Read Only, just click on the “Open this site” button and you are back in business!
Even though, this option comes under Site Administration, it makes all the sub sites read only too
Hope this helps 🙂