Guest User

Untitled

a guest
Sep 10th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. $FolderToBreak = "/sitename/Documents/testtt123"
  2. $userToRemove = "user@domain.com"
  3.  
  4. ##Variables for Processing
  5. $SiteUrl = "https://sitename.sharepoint.com/sitename"
  6. $UserName="globaladmin@domain.com.au"
  7. $Password ="xxxxxx"
  8.  
  9. Add-Type -Path "c:CSOMMicrosoft.SharePoint.Client.dll"
  10. Add-Type -Path "c:CSOMMicrosoft.SharePoint.Client.Runtime.dll"
  11.  
  12. #Setup Credentials to connect
  13. $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
  14.  
  15. Try {
  16. #Set up the context
  17. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
  18. $Context.Credentials = $credentials
  19.  
  20. #Get the List Root Folder
  21. $Folder=$Context.web.GetFolderByServerRelativeUrl($FolderToBreak)
  22. #break inheritance just incase, should already be broken to share user to begin with
  23. $Folder.ListItemAllFields.BreakRoleInheritance($true,$false)
  24.  
  25. #want to remove permission from the user $userToRemove from $folder but roleassignements doesnt have a .remove, and now i am lost....
  26. $Folder.ListItemAllFields.RoleAssignments....
  27.  
  28. }
  29. catch {
  30. write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
  31. }
Add Comment
Please, Sign In to add comment