SharePoint Online: How to Prevent Users from Editing Pages?
Requirement: Disable the ability to edit site pages in SharePoint Online from site members.
How to Prevent Users from Editing Pages in SharePoint Online?
By default, members of the SharePoint Online site can edit any page, including the Home page. At times, this creates unnecessary issues, and we wanted to stop users from editing site pages. So, the overall idea here is: Break permission inheritance of the “Site Pages” library, edit the permissions of the default members group of the site by removing “Edit” permissions and add “Read” permissions to them.
Here is the step-by-step procedure to stop users from editing site pages.
- Browse to your SharePoint site >> Click on Settings Gear >> Choose “Site Contents”
- Click on “Site Pages” from the list of available lists and libraries.
- Click on the settings Gear >> Choose “Library Settings”.
- Under the library settings page, click on “Permissions for this document library”.
- Now, We have to break permission inheritance. Click on “Stop Inheriting Permissions”.
- Locate and select the checkbox next to the Members Group of the site, in my case its “Operation Site Members” as I’m in the “Operations” site.
- Click on “Edit User Permissions” button in the ribbon.
- In the edit user permissions page, uncheck the checkbox next to Edit and check it for “Read”.
- Click on OK button to save your changes.
So now, We have removed edit permissions from members of the site and granted read permissions so that users won’t be able to edit the page while they still have read access to browse through.
PowerShell to prevent users from editing pages in SharePoint Online
The above steps can be automated with the help of PowerShell as:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Operations"
$ListName = "Site Pages"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Default Members Group
$MembersGroup = Get-PnPGroup -AssociatedMemberGroup
#Break Permission Inheritance of the List
Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments
#Remove "Edit" permission from the list
Set-PnPGroupPermissions -Identity $MembersGroup -List $ListName -RemoveRole "Edit"
#Grant "Read" permission to the Group
Set-PnPListPermission -Identity $ListName -AddRole "Read" -Group $MembersGroup
Write-Host "Removed 'Edit' Permissions and Granted 'Read' on 'Site Pages' to $($MembersGroup.Title). " -foregroundcolor Green
}
Catch {
write-host -f Red "Error Setting Permissions!" $_.Exception.Message
}
God bless you!!