Sunday, December 2, 2012

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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...