Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function replacePremissions($fld){
- if($fld.Item -ne $null -and $fld.Item.HasUniqueRoleAssignments ){
- Write-Host "D:$($fld.ServerRelativeUrl)"
- updatePremissionsNotDelete($fld.Item)
- }
- if($fld.SubFolders.Count -gt 0){
- foreach($d in $fld.SubFolders){
- replacePremissions $d
- }
- }
- }
- function updatePremissionsNotDelete($itm){
- $perms2replace = @("Full Control", "Contribute")
- $permReplaceWith = "Contribute not Delete"
- $rdNew = $w.RoleDefinitions|?{$_.Name -eq $permReplaceWith }
- foreach($rdName in $perms2replace){
- $rd = $w.RoleDefinitions|?{$_.Name -eq $rdName }
- foreach($ra in $itm.RoleAssignments){
- if($ra.RoleDefinitionBindings.Contains($rd)){
- $ra.RoleDefinitionBindings.Remove($rd)
- $ra.RoleDefinitionBindings.Add($rdNew)
- }
- $ra.Update()
- }
- }
- }
- $w = Get-SPWeb http://xxxxxx.com/sites/Policies
- $lists = @( "KEMH", "MWI")
- foreach($list in $lists){
- $l = $w.Lists.TryGetList($list)
- if($l -eq $null){
- throw "List not found: $($list)"
- }
- updatePremissionsNotDelete $l
- $rf = $l.RootFolder
- replacePremissions $rf
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement