Created
April 15, 2015 06:51
-
-
Save AdamNaj/f9a52748b318d23813b8 to your computer and use it in GitHub Desktop.
ACL Manipolation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Add-ItemAccess{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] | |
[ValidateNotNullOrEmpty()] | |
[Sitecore.Data.Items.Item]$item, | |
[Parameter(Position=1, Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$roleName) | |
$myRole = Get-Role $roleName | |
# Get the current accessrules | |
$accessRules = $item.Security.GetAccessRules(); | |
# Apply read access for the "roleName " to the current item | |
# and all it's children | |
$accessRules.Helper.AddAccessPermission($myRole, | |
[Sitecore.Security.AccessControl.AccessRight]::ItemRead, | |
[Sitecore.Security.AccessControl.PropagationType]::Any, | |
[Sitecore.Security.AccessControl.AccessPermission]::Allow); | |
# Write the rules back to the item | |
$item.Editing.BeginEdit(); | |
$item.Security.SetAccessRules($accessRules); | |
$item.Editing.EndEdit() | Out-Null | |
} | |
#Now you can simply pipe items into the function as follows (item /sitecore/content/home item (rights cascading)): | |
Get-Item master:\content\home | Add-ItemAccess -RoleName sitecore\Designer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment