Skip to content

Instantly share code, notes, and snippets.

@PshMike
Last active October 4, 2021 18:24
Show Gist options
  • Save PshMike/69561fd896a440a07ef858d69b146fd8 to your computer and use it in GitHub Desktop.
Save PshMike/69561fd896a440a07ef858d69b146fd8 to your computer and use it in GitHub Desktop.
Set AD Group ACL
$GroupObject = Get-ADGroup 'MyGroupName'
$NTPrincipal = Get-ADUser 'myUserName'
if ($GroupObject -and $NTPrincipal) {
$acl = Get-Acl "AD:$($GroupObject.distinguishedName)"
$identity = [System.Security.Principal.IdentityReference] $NTPrincipal.SID
$adRights = [System.DirectoryServices.ActiveDirectoryRights]::WriteProperty -bor [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl
$type = [System.Security.AccessControl.AccessControlType] "Allow"
$inheritanceType = [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None
$ACE = New-Object System.DirectoryServices.ActiveDirectoryAccessRule $identity,$adRights,$type,$inheritanceType
$acl.AddAccessRule($ace)
Set-Acl -AclObject $acl -Path "AD:$($GroupObject.distinguishedName)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment