Answered by:
Delete Security role with Powershell from a Document Library

Question
-
Hi All,
I'm strungling with the following, which I though would be a simple enough task.
I have a couple of hundred sites, on which I have a document library (inheritance broken) and I need to remove a group from each of this document libraries. This is on SharePoint Online, so I need to use the CSOM.
After some stungles I came up with this:
$Username = "UserName" $Site = "https://testurl/sites/TEST" $Password = Read-Host -Prompt "Please enter your password" -AsSecureString #Add references to SharePoint client assemblies and authenticate to Office 365 site Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" $Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password) $Context.Credentials = $Creds $Web = $Context.Web $Context.Load($web) $curlist=$context.Web.Lists.GetByTitle("Documenten") $Context.Load($curlist.RoleAssignments) $Context.ExecuteQuery() foreach ($ra in $curlist.RoleAssignments) { $p=$ra.member $Context.Load($p) $Context.ExecuteQuery() write-host $p.LoginName -ForegroundColor Cyan if ($p.LoginName -eq "Projects") { Write-Host "--> "$p.loginname -ForegroundColor Green $ra.DeleteObject() $ra.Update() } }
I does not generate any errors, and lists the security roles.. But I'm unable to delete the role 'Projects'...
Anybody a idea in which direction I need to search?
thks
BartMonday, August 10, 2015 11:01 AM
Answers
-
Hi
see if this help
http://sharepoint.stackexchange.com/questions/57973/remove-non-full-controlled-permission-sharepoint-groups-from-a-sharepoint-list-u
Rajendra Singh
sharepoint with my way
Walking on water and developing software from a specification are easy if both are frozen
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful- Edited by RajendraPratap Singh Tuesday, August 11, 2015 8:09 AM
- Marked as answer by Patrick_Liang Wednesday, September 9, 2015 2:26 AM
Tuesday, August 11, 2015 8:07 AM
All replies
-
Hi
see if this help
Rajendra Singh
sharepoint with my way
Walking on water and developing software from a specification are easy if both are frozen
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful- Proposed as answer by croute1 Monday, August 10, 2015 12:37 PM
Monday, August 10, 2015 11:55 AM -
Hi Rajendra,
Thanks for you reply. This will reset all items in a Document library. I just want to remove a unique role at the Document library level. Is this not possible?
So I have a Document Libary with unique permisions and 4 groups. All I need to do for example is remove "Group 3" and leave everything else intact.
Is your example adaptable for this?
Bart
Monday, August 10, 2015 2:16 PM -
Hi
see if this help
http://sharepoint.stackexchange.com/questions/57973/remove-non-full-controlled-permission-sharepoint-groups-from-a-sharepoint-list-u
Rajendra Singh
sharepoint with my way
Walking on water and developing software from a specification are easy if both are frozen
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful- Edited by RajendraPratap Singh Tuesday, August 11, 2015 8:09 AM
- Marked as answer by Patrick_Liang Wednesday, September 9, 2015 2:26 AM
Tuesday, August 11, 2015 8:07 AM