Hi,
We have prepared a Power Shell command using Client Side scripts as per client requirements. The client did not had access to the SharePoint Server. So, PS commands with server side scripts was out of scope.
The client requirement was to delete all the permissions on the list that was being inherited from site. Since the number of users were huge, so deleting all the users using ribbon was not possible.
Please have a look at the scripts below and let me know your feedback. If you have better suggestion than this, please let me know.
#################################################
#location of client dlls on users' local system
$loc = "C:\SharePoint\ClientDLL"
//SharePoint Site URL
$siteUrl = ""
#Write your Login ID
$loginname = ""
#Write the Name of the List
$listname = ""
Set-Location $loc
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Write-Host "Please enter password for $($siteUrl):"
$pwd = Read-Host -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
Try
{
# Remove or replace line below to change authentication method
$ctx.Credentials = New-Object System.Net.NetworkCredential($loginname, $pwd)
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
#Write-Host "Current web title is '$($web.Title)', $($web.Url)"
$list = $Web.Lists.GetByTitle($listname);
$ctx.Load($list);
$ctx.ExecuteQuery();
Write-Host "Deleting Permissions on List : $($list.Title)"
if($list.HasUniquePermissions)
{
#Write-Host "Has Unique Permissions"
$list.ResetRoleInheritance()
$list.BreakRoleInheritance($false, $true)
Write-Host "Permissions deleted" -foregroundcolor Green
}
if(-not $list.HasUniquePermissions)
{
#Write-Host "Does not has Unique Permissions"
$list.ResetRoleInheritance()
$list.BreakRoleInheritance($false, $true)
Write-Host "Permissions deleted" -foregroundcolor Green
}
}
Catch
{
Write-Host "Some Error, Please Contact Administrator" -foregroundcolor Red
return
}
$list.Update()
$ctx.ExecuteQuery();
Regards,
S