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 https://sharepoint.crescent.com
  3. Retrieve Site lock status with PowerShell:
    Get-SPSite “https://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 "https://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 https://sharepoint-sitecollection-url -LockState Unlock 

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

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

  • 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
  • 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
  • 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 “https://sitecollection.test.com” -LockState Unlock
    then Get-SPSite “https://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

Your email address will not be published. Required fields are marked *