Getting site read and lcoked sites from group of site collections list

sns 9,251 Reputation points
2022-11-16T18:32:55.627+00:00

I would like to retrieve read and locked site collections from bunch of site collections available in my CSV file from particular web application.
Could you please share script for this? Thank you

Microsoft 365 and Office | SharePoint Server | For business
{count} votes

Answer accepted by question author
  1. Renjie Sun-MSFT 2,861 Reputation points Microsoft Employee
    2022-11-17T08:43:19.74+00:00

    Hi @sns ,

    You could refer this Powershell command template to export site collection URLs from CSV file:)

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
      
    $CSVFile="C:\test\SitesStatusList.csv"  
     
      
    Import-csv "C:\test\SitesList.csv" | ForEach-Object {  
      
      
    $Site = Get-SPSite $_.Url  
    if ($Site.ReadOnly -eq $false -and $Site.ReadLocked -eq $false -and $Site.WriteLocked -eq $false)  
    {  
        $Results = "Unlocked"  
    }  
      
    elseif ($Site.ReadOnly -eq $true -and $Site.ReadLocked -eq $false -and $Site.WriteLocked -eq $true)  
    {     
        $Results = "Read-Only"  
    }  
    #Adding Content Prevented?  
    elseif ($Site.WriteLocked -eq $true -and $Site.ReadLocked -eq $false -and $Site.ReadOnly -eq $false)  
    {     
        $Results = "Adding Content Prevented"  
    }  
         
    elseif ($Site.ReadOnly -eq $null -and $Site.ReadLocked -eq $null -and $Site.WriteLocked -eq $null)  
    {  
        $Results = "No Access"   
    }  
      
    New-Object -TypeName PSObject -Property @{  
                 SiteName = $Site.RootWeb.Title  
                 Url = $Site.Url  
                 SiteStatus = $Results}  
    }| Export-CSV $CSVFile -NoTypeInformation  
    

    Use this command you could export the results to a new CSV file. If you only want to display the results, the command of exporting to a new CSV file could be removed.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.