How To Resolve The Issues When Site On Maintenance Mode/Read Only Mode

I came across an interesting issue recently, where our production sites flag notification for every user was “We apologize for any inconvenience”.
 
This issue, for regarding a scheduled backup task scheduler, failed orwas  interrupted for any resign.
 
In my case, at the time of scheduler, the drive did not have sufficient space.  The backup process was abnormally terminated.
 
This resulted in all Sites being in Read only mode & the following message would show up, when users browsed to the site.
 
“We apologize for any inconvenience, but we've made the site read only, while we're making improvements."
 
How To Resolve The Issues When Site On Maintenance ModeRead Only Mode
 
Go to "Site collection Quota & locks" in Central Admin.  Here is what the Status looks like.  It is locked as “Read only" and all settings are greyed out, even though you have administrator permission.
 
How To Resolve The Issues When Site On Maintenance ModeRead Only Mode
 
Here, is more on this behaviour and how to get out of this situation.
 
In SharePoint 2013, microsoft introduced a property MaintenanceMode, for Spsite object, which indicates the site is undergoing Maintenance and is read only.  SPSite.MaintenanceMode flag, can be set on a site for several reasons, like content database is in read only state, site collection is being upgraded, and backed up or moved.
 
If a site gets into a state where the action that set this has terminated in a way where this is still set, we run into this situation.
 

Solutions

 
The way to clear this flag notification is to use the ClearMaintenanceMode method, in SpSiteAdministration object.  Here, is how it can be done, via SharePoint Management Shell.
 
Option Command 1
 
#Run this command search site separately or run one by one all top level sites, if we have multiple top level sites/ Web application.
 
Step 1
  1. $Admin = new-object  
  2. # SiteName “http://myweb.adnec.local/”.  
  3. Microsoft.SharePoint.Administration.SPSiteAdministration(‘SiteName’)   
Step 2
  1. $Admin.ClearMaintenanceMode() 
Step 3
  1. $site.MaintenanceMode  
Option Command 2
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
  2. #Clears all the maintenance modes for all Site Collections in the farm.  
  3. $webapp = Get-SPSite -Limit ALL  
  4. foreach ($site in $webApp){  
  5.    $Admin = new-object Microsoft.SharePoint.Administration.SPSiteAdministration($site.url)  
  6.    $Admin.ClearMaintenanceMode()  
  7. }