How to make all the Sharepoint online sites read only

SR VSP 1,226 Reputation points
2022-01-10T23:21:02.44+00:00

Hi Guys,

Can you advise how to make all the sites in the Tenant to "Read Only" at a time using PS script

I'm using below command for a specific site collection

Set-SPOSite https://contoso.sharepoint.com/sites/Testsite1 -LockState ReadOnly

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,675 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Elsie Lu_MSFT 9,761 Reputation points
    2022-01-11T07:24:18.127+00:00

    Hi @SR VSP ,

    Usually we do not recommend doing such a setting at the tenant level. I suggest that you can set the sites you want in a csv file and use PowerShell to make those sites read-only.

    ==========================================

    Try this method:

    CSV file Sample:

    Url
    "http://myServer.com/sites/ABC/"
    "http://myServer.com/sites/XYZ/"
    "http://myServer.com/sites/VCS/"
    "http://myServer.com/sites/BVC/"

    PS Script

    Cls  
      
    Add-PSSnapin Microsoft.SharePoint.PowerShell  
      
    $SitesColl = import-csv "C:\Temp\2020\SiteCollections.csv"  
      
      
    # Set Read Only  
    foreach($Site in $SitesColl)  
    {  
         
       Write-Host "Set Readonly:" $Site.Url  
         
       Set-SPSite -Identity $Site.Url -LockState "ReadOnly"     
       #Set-SPSite -Identity $Site.Url -LockState "Unlock"   
    }  
      
      
    # Check ReadOnly Status  
    foreach($Site in $SitesColl)  
    {  
       $Mysite=Get-SPSite -Identity $Site.Url    
      
       Write-Host "ReadOnly Status:" $MySite.ReadOnly  
    }  
    

    See reference:
    several site collection add into "Readonly" mode using powershell script


    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.