Last active
August 29, 2015 14:03
-
-
Save jeffpatton1971/d838bedcb4025d804106 to your computer and use it in GitHub Desktop.
Copy AD ACL's for one principal to another principal
This file contains hidden or 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
# | |
# Copy AD ACL Rules | |
# | |
param | |
( | |
$adPath, | |
$secPrincipal, | |
$newPrincipal | |
) | |
$Permissions = ([adsi]$adPath).ObjectSecurity; | |
if ($Permissions) | |
{ | |
$Rules = $Permissions.Access |Where-Object -Property IdentityReference -eq $secPrincipal; | |
$IdentityReference = New-Object System.Security.Principal.NTAccount($newPrincipal); | |
$NewRules = @() | |
foreach ($Rule in $Rules) | |
{ | |
$NewRule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule( | |
$IdentityReference, | |
$Rule.ActiveDirectoryRights, | |
$Rule.AccessControlType, | |
$Rule.ObjectType, | |
$Rule.InheritanceType, | |
$Rule.InheritedObjectType); | |
$NewRules += $NewRule; | |
$Permissions.SetAccessRule($NewRule); | |
} | |
} | |
return $NewRules; | |
else | |
{ | |
Write-Host "No permissions returned from $($adPath), please verify that you have typed the path in properly"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage is pretty straightforward
copy-adacl.ps1 -adpath "LDAP://cn=thing,ou=folder,dc=company,dc=com" -secPrincipal "company\admin" -NewPrincipal "company\otheradmin"