Skip to content

Instantly share code, notes, and snippets.

@jeffpatton1971
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffpatton1971/d838bedcb4025d804106 to your computer and use it in GitHub Desktop.
Save jeffpatton1971/d838bedcb4025d804106 to your computer and use it in GitHub Desktop.
Copy AD ACL's for one principal to another principal
#
# 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";
}
@jeffpatton1971
Copy link
Author

Usage is pretty straightforward

copy-adacl.ps1 -adpath "LDAP://cn=thing,ou=folder,dc=company,dc=com" -secPrincipal "company\admin" -NewPrincipal "company\otheradmin"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment