SharePoint 2016: Set Site Collection to Read Only
At times, we may require to set site collections to read-only mode to prevent any add/edit/delete operations on the site’s content. During a SharePoint migration, we decided to set sites to read only to restrict any updates. How to set site collection to read only in SharePoint 2013?
Set SharePoint 2013 / 2016 site collection to read using Central Administration:
Usually, making SharePoint 2013 site collections to read only is done at the SharePoint Central administration site.
- Go to Central Administration >> Select Application Management >> Configure quotas and locks
- Choose the site collection you want to set on Read-only mode and select the option “Read-Only”. Choose farm administrator controlled or site collection administrator controlled options accordingly.
- Enter the lock information and click “OK”
Fortunately, unlike its previous versions, SharePoint 2013 displays a banner “This site is read only at the farm administrator’s request” to notify end users – when site collections are in read-only mode!
Once sites are read-only, you may notice certain controls on ribbons, menus are disabled. But site content can be accessed as usual.
Set Site Collection Read Only with PowerShell
We can make a SharePoint site read only using PowerShell. Open SharePoint Management Shell. Enter the following cmdlet:
Set-SPSite -Identity "Site-Collection-URL" -LockState "ReadOnly"
How to set all SharePoint sites to Read-only?
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
#Get all Site Collections
$SitesColl = Get-SPSite -limit All
#Loop through all site collections
ForEach($Site in $SitesColl)
{
Set-SPSite -Identity $site.Url -LockState "ReadOnly"
#You can also use: Set-SPSiteAdministration -LockState "ReadOnly" -Identity $Site.URL
}
Unlocking SharePoint 2013 read only site collections
To reverse the Read only mode, Return to the SharePoint Central Administration’s Site Collection Quotas and Locks page and choose “Not locked”. We can unlock the site collection using PowerShell by entering the command:
Set-SPSite -Identity "Site-Collection-URL" -LockState "Unlock"
You can use STSADM also to set SharePoint 2013 site in read only mode
To make a SharePoint site read-only, Enter:
Stsadm -o SetSiteLock -url “Site-Collection-URL” -lock ReadOnly
To undo read-only, use:
Stsadm -o SetSiteLock -url “Site-Collection-URL” -lock none
SharePoint site locks are explained in my another article: Site Collection Locks in SharePoint
It’s also possible to make sites to read only using SharePoint Server Object Model: SPSite.ReadOnly = true. Setting up sites to read-only can be done at SQL Server also at the content database level.
To make the web application or entire farm to Read only, refer: Set SharePoint Web Application or Farm to Read Only Mode
This site has pretty much become a one-stop shop for me. Great work Salaudeen!
I have a question about the script on this page. I set all of the sites to read only for a maintenance window using this script, but when I went to unlock them, it skipped 150 sites that have spaces in the URL. I get this error:
$SPSite = get-spsite $Site
~~~~~~~~~~~~~~~~
CategoryInfo : InvalidData: (Microsoft.Share…SPCmdletGetSite:SPCmdletGetSite) [Get-SPSite],
SPCmdletPipeBindException
FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
>> ParameterBinding(Trace-SteroidsOutput): name=”InputObject”; value=”Cannot find an SPSite object with Id or Url: “https://customsolutions.domain.com/sites/LastName, FirstName MiddleName”.”
get-spsite : Cannot find an SPSite object with Id or Url:
“https://customsolutions.domain.com/sites/LastName, FirstName MiddleName”.
At C:UsersMeDocumentsWindowsPowerShellScriptsSet-SiteLock&LockIssue.ps1:28 char:13
$SPSite = get-spsite $Site
~~~~~~~~~~~~~~~~
CategoryInfo : InvalidData: (Microsoft.Share…SPCmdletGetSite:SPCmdletGetSite) [
Get-SPSite], SPCmdletPipeBindException
FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
Any way around this?
I know this is an old post, but did you try changing the spaces to %20 (ASCII code for a space)?
How do we change the Read only banner at the top? I thought that the message in central admin when you lock the site would do the trick, but we still have the boring “This site is read only at the farm administrator’s request.”
I want to set site to ‘site admin controlled read only’ using powershell but it is setting it in farm admin controlled read only by default. Through UI I can change but how to do it through powershell
Wow, I’ve used two of your scripts today! Thanks for posting. Adding your site to my SharePoint Favorites.