Set SharePoint Online Site to Read Only using PowerShell
Requirement: Set a SharePoint Online site to read only using PowerShell.
How to make a SharePoint Online site read only?
If you have a SharePoint Online site that you would like to make read-only, PowerShell makes it easy! This blog post will show you how to set a SharePoint Online site to read-only using PowerShell.
What are some reasons, why you would like to make sites read-only? Maybe you want to protect sensitive data from being edited or deleted by other people in your organization, or you want to make your site read-only for compliance reasons. Although you can set the site permissions of all users to read-only, This doesn’t stop site collection administrators from altering the content. But putting the site to read-only prevents everyone, including site collection administrators, from editing content but still allows them access so that they can view the changes.
During a migrated project, we wanted to set a SharePoint Online site collection to read-only to enforce Data consistency. To make SharePoint Online site collection read-only, use this PowerShell script in SharePoint Online Management Shell.
#Set Parameters
$AdminCenterURL="https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to SharePoint Online
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)
#PowerShell to set sharepoint online site to read only
Set-SPOSite -Identity $SiteURL -LockState ReadOnly
Once the execution of the above script is completed, you’ll find a message appearing on top of the site: “SharePoint sites are read-only right now while we do some maintenance. We apologize for the inconvenience.”
To unlock the site collection, use the following:
#Unlock site from read only mode
Set-SPOSite -Identity $SiteURL -LockState Unlock
PnP PowerShell to Set a Site Collection to Read-Only Mode
Here is how to lock a SharePoint Online site collection with PnP PowerShell:
#Parameters
$TenantURL = "https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/volver"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $TenantURL -Interactive
#Set Site to Read-only
Set-PnPTenantSite -Url $SiteURL -LockState ReadOnly
Write-Host "Site set to Read-Only Mode Successfully!" -f Green
}
Catch {
Write-Host -f Red "Error:"$_.Exception.Message
}
Here is another post on making site read only using site policy: SharePoint Online: Make Site Collection Read only using Site Policies?
Wrapping up
In conclusion, setting a SharePoint Online site to read-only using PowerShell is quick and straightforward. By following the steps outlined in this article, you can use PowerShell to easily set the SharePoint Online site to read-only for all users. This is a useful tool for organizations that need to temporarily limit access to a site, or for those who want to ensure that users cannot make changes to a site’s content. The use of PowerShell also provides a convenient way to automate the process, making it easier to manage multiple sites at once.
Thank you.
Thank you very much! This saved my bread.