script to get site status from particular db

sns 8,536 Reputation points

Please help me in getting the script to get the list of site collection names with their site lock status from particular db in excel sheet. thank you

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,500 questions
0 comments No comments
{count} votes

Accepted answer
  1. Allen Xu_MSFT 13,571 Reputation points

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. sns 8,536 Reputation points

    Hi Allex Xu,

    Will you train SharePoint powershell?

    0 comments No comments