AnswerBun.com

How to set Sharepoint Onprem site collection to Readonly with powersehll csom?

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 )
$clientContext.ExecuteQuery()
$site.ReadOnly =$true # got an error ReadOnnly property is readonly.

SharePoint Asked by Elina on January 7, 2021

2 Answers

2 Answers

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.


UPDATE:

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.

Answered by Chelsea_MSFT on January 7, 2021

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.

Answered by Callum Crowley on January 7, 2021

Add your own answers!

Related Questions

External Sharing – Sharepoint Mobile App

2  Asked on December 3, 2020 by dilip-kumar-yadav

     

Cascading dropdown list in SPFx web part

1  Asked on November 29, 2020 by burre-ifort

       

Project Server Web App Database Provisioning failed

2  Asked on November 29, 2020 by sukhdev-zala

 

How to update ShqrePoint Group name?

2  Asked on November 26, 2020 by kaddrik

     

SharePoint Framework to read term from TermSet

1  Asked on November 8, 2020 by user92615

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.