Skip to content

Instantly share code, notes, and snippets.

@techdecline
Created September 22, 2020 07:21
Show Gist options
  • Select an option

  • Save techdecline/09f06d712a64c3c42b802badd99aa9d5 to your computer and use it in GitHub Desktop.

Select an option

Save techdecline/09f06d712a64c3c42b802badd99aa9d5 to your computer and use it in GitHub Desktop.
# Variables
###########
$siteServerName = "CMTP_Server1"
$domainLDAP = "dc=decline,dc=lab"
# System Management Container
#############################
New-ADObject -Name "System Management" -Type Container -Path ("Cn=system," + $domainLDAP)
$containerDN = "CN=System Management,Cn=system," + $domainLDAP
$siteServerSID = (Get-ADComputer $siteServerName).SID
$aclObj = Get-Acl AD:\${containerDN}
$objACE = New-Object System.DirectoryServices.ActiveDirectoryAccessRule($siteServerSID,"GenericAll","Allow", [System.Security.AccessControl.InheritanceFlags]::ContainerInherit, [guid]'00000000-0000-0000-0000-000000000000')
$aclObj.AddAccessRule($objACE)
Set-acl -AclObject $aclObj "AD:${containerDN}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment