TransWikia.com

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

SharePoint Asked by Elina on January 7, 2021

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.

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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP