Hi @Agarwal, Komal
Per my research, there is no direct way to set the SharePoint folder to read-only! The read-only mode can be set only on SharePoint site collections (How to Make a Site Collection Read-Only) or on content databases (Set SharePoint Content Database to Read Only Mode). However, we can make a SharePoint library to read-only by replacing all user’s permissions into “Read-only”. The following script will restrict users from making changes to the list or library.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration Parameters
$SiteURL="https://intranet.crescent.com/"
$ListName= "Projects"
#Get the Web and List
$Web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)
#Break Permissions of the List
If ($List.HasUniqueRoleAssignments -eq $false)
{
$List.BreakRoleInheritance($true)
}
#Get Read Permission Level
$ReadPermission = $web.RoleDefinitions["Read"]
#Get All User & Groups granted Permissions to the List
ForEach ($RoleAssignment in $List.RoleAssignments)
{
Write-host "Resetting Permissions for :"$RoleAssignment.Member.Name -f Yellow
#Replace All other permissions with "Read" if its not granted already
$RoleDefinitionBindings = $RoleAssignment.RoleDefinitionBindings
Foreach($RoleDefBinding in $RoleDefinitionBindings)
{
IF( ($RoleDefBinding.Name -ne "Read") -and ($RoleDefBinding.Name -ne "Restricted Read") -and ($RoleDefBinding.Name -ne "View Only") -and ($RoleDefBinding.Name -ne "Limited Access") )
{
#Grant Read ACcess if its not present
If(!($RoleAssignment.RoleDefinitionBindings.Contains($ReadPermission)))
{
$RoleAssignment.RoleDefinitionBindings.Add($ReadPermission)
$RoleAssignment.Update()
Write-host "Added Read Permissions to "$RoleAssignment.Member.Name -ForegroundColor Green
}
}
else
{
continue;
}
}
#Remove All permissions other than Read or Similar
$RoleDefinitionBindings = $RoleAssignment.RoleDefinitionBindings
For($i=$RoleDefinitionBindings.Count-1; $i -ge 0; $i--)
{
$RoleDefBinding = $RoleAssignment.RoleDefinitionBindings[$i]
IF( ($RoleDefBinding.Name -eq "Read") -or ($RoleDefBinding.Name -eq "Restricted Read") -or ($RoleDefBinding.Name -eq "View Only") -or ($RoleDefBinding.Name -eq "Limited Access") )
{
continue;
}
Else
{
$RoleAssignment.RoleDefinitionBindings.Remove($RoleAssignment.RoleDefinitionBindings[$i])
$RoleAssignment.Update()
Write-host Removed $RoleDefBinding.Name Permissions from $RoleAssignment.Member.Name -ForegroundColor Red
}
}
}
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.