script to get site status from particular db

sns 9,226 Reputation points
2021-03-09T11:08:04.747+00:00

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,818 questions
0 comments No comments
{count} votes

Accepted answer
  1. Allen Xu_MSFT 13,776 Reputation points
    2021-03-10T06:07:21.817+00:00

    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:
    76088-image.png


    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 9,226 Reputation points
    2021-03-10T06:29:57.707+00:00

    Hi Allex Xu,

    Will you train SharePoint powershell?

    0 comments No comments