Hi @sns ,
To get lock status for all SharePoint Site Collections from a specific Content Database and write the results to a .csv file, please take a reference to the following PowerShell commands.
Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue
#Get All Site Collections of a web app
$Sites = Get-SPSite -ContentDatabase "<replace here with your content database name>" -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 C:\LockStatus.csv -Append
}
The result .csv file will be automatically generated under C:\LockStatus.csv. Test result in my end:
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.