Check Lock Status for All Site Collections in SharePoint

End user came with a compliant: “I’m receiving ‘HTTP 403: The Website declined to Show this webpage’ in some sites”, in an intranet collaboration environment. Ah! This is because: site is locked with “No Access”.

403 The Website declined to Show this webpage - SharePoint Site Locks

How to Check Site Lock Status?

  1. You can navigate to: Central Administration > Application Management > Configure Quotas and Locks to get lock status.
  2. Get Lock status with STSADM
    stsadm -o getsitelock -URL http://sharepoint.crescent.com
  3. Retrieve Site lock status with PowerShell:
    Get-SPSite “http://sharepoint.crescent.com” | Select ReadOnly,Readlocked,WriteLocked

But for this case, End-user doesn’t remember the URL. There are 5000+ site collections. How do I find which site collection has been locked with “No Access”? We have to retrieve lock status for all site collections. PowerShell comes to rescue again:

PowerShell Script to Get Lock status for all Site Collections:

Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue

#Get All Site Collections of a web app
$Sites = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -limit all | foreach {

#Check Lock Status

#No Locks Applied?
if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false) 
{
   $Result ="Unlocked"
}
#Read-only Lock?
elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true) 
{
   $Result = "Read-Only"
}
#Adding Content Prevented?
elseif ($_.WriteLocked -eq $true -and $_.ReadLocked -eq $false -and $_.ReadOnly -eq $false) 
{
   $Result = "Adding Content Prevented"
}
#No Access?
elseif ($_.ReadOnly -eq $null -and $_.ReadLocked -eq $null -and $_.WriteLocked -eq $null) 
{
   $Result="No Access"
}

#Write the Result to CSV file separeted with Tab character
$_.RootWeb.Title +"`t" + $_.URL + "`t" + $Result | Out-File LockStatus.txt -Append
}
To unlock a site collection use:
Set-SPSite -Identity http://sharepoint-sitecollection-url -LockState Unlock 

Fore more information on SharePoint site locks refer my post: Site Collection Locks in SharePoint

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

4 thoughts on “Check Lock Status for All Site Collections in SharePoint

  • November 17, 2020 at 5:39 AM

    For the read-only lock status, I just noticed that only following condition works where WriteLocked should also be $false

    #Read-only Lock?
    elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false)
    {
    $Result = “Read-Only”
    }

    Reply
  • November 10, 2020 at 5:13 PM

    Hi Salaudeen

    Thanks so much for your respond and solution. That’s is what I need. I spent lot of time searching for answer and could not find anything related to the issue I had described. Until now. I really appreciate your helps.

    Swanl

    Reply
  • November 10, 2020 at 12:42 AM

    Hi

    I terminated a PowerShell site backup early and now the site is in ReadOnly state and I could not change to unlock in CA.
    So I tried to unlock the site with Set-SPSite -Identity “http://sitecollection.test.com” -LockState Unlock
    then Get-SPSite “http://sitecollection.test.com” | select Readonly, Readlocked, WriteLocked

    ReadOnly still show True ReadLock show False WriteLocked show False

    I tried to change the site property $site.ReadOnly = False but the property didnot make the change ..

    Could you please help. How do I set ReadOnly to False?

    Swanl

    Reply

Leave a Reply