I want to make SharePoint on-premise and SharePoint online site collection to Readonly. For SharePoint online i can able to achieve with Pnp commands.But on-premise is not working.

code i have used for SharePoint online :

Connect-PnPOnline -url $site -Credentials $credentials
Set-PnPSite -Identity $site  -LockState ReadOnly

How we can set on-premise site to readonly. I have tried like this , this also giving error.

$site = $clientContext.Site
$clientContext.Load($site )
$site.ReadOnly =$true # got an error ReadOnnly property is readonly.

You can use the following PowerShell command for SharePoint on-premises:

Set-SPSite -Identity "<SiteURL>" -LockState "ReadOnly"

References:Set-SPSite. / SharePoint 2013: Set Site Collection to Read Only.


Here is another sample script which can be executed using Windows PowerShell:

Add-PSSnapin "Microsoft.sharepoint.powershell"  
$Site = Get-SPSite -Identity “<SiteURL>”
$Site.ReadOnly = $true

I suppose the problem is how you get the site. The Site.ReadOnly property is still in function.

| improve this answer | |
  • but this command will execute only in SharePoint Management Shell.Is that any other options with csom powersehll. – Elina Jul 15 at 4:11
  • @Elina Please see the updated answer. – Chelsea_MSFT Jul 21 at 2:05

This can be achieved using Site Policies:

  1. Create a site policy with the option "The site collection will be read only when it is closed." ticked. Ensure that you do not set the site to close or delete automatically unless this is desired.
  2. Using the UI, the policy can be applied by going to Site Settings > Site Closure and Deletion, set the policy and click ok. Navigate away from the page.
  3. Return to the Site Closure and Deletion page and close the site.
  4. The site should now be read only. It can be reopened if necessary.

Applying the policy and site closure can be done using CSOM if required.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.