VBScript to enable/disable “manager can update membership list” checkbox
Managing this checkbox proves harder than expected. The managedBy value is an attribute, but the checkbox is a delegation of control setting on the member attribute of the group object you put the managedBy value on.
'Usage: cscript "CN=Group,OU=Groups,DC=Tools4ever,DC=local" DC01.tools4ever.local T4EVMDEMO 1
'Make sure the managedBy attribute is already set, as this script reads the user from that attribute and adds the appropriate delegation of the member attribute to the group object
strGroup = wscript.arguments(0) 'DN of Group
strDomainController = wscript.arguments(1) 'DC FQGN used to bind to group
strDomainNT4 = wscript.arguments(2) 'NETBIOS domain name for the group
intEnabled = wscript.arguments(3) '1 for enabled, 0 for disabled
Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5
Const ADS_RIGHT_DS_WRITE_PROP = &H20
Const ADS_ACEFLAG_INHERIT_ACE = &H00002
Const ADS_ACEFLAG_DONT_INHERIT_ACE = &H0
Const ADS_FLAG_OBJECT_TYPE_PRESENT = &H01
Const ADS_OBJECT_WRITE_MEMBERS = “{BF9679C0-0DE6-11D0-A285-00AA003049E2}”
Set objGroup = GetObject(“LDAP://” & strDomainController & “/” & strGroup)
Set objSecurityDescriptor = objGroup.Get(“ntSecurityDescriptor”)
Set objDACL = objSecurityDescriptor.DiscretionaryACL
Set objUser = GetObject(“LDAP://” & objGroup.Get(“managedBy”))
if intEnabled = 0 then
For Each objACE in objDACL
If InStr(1, objACE.Trustee, objUser.Get(“sAMAccountName”), VbTextCompare) Then
objDACL.RemoveAce(objACE)
End If
Next
else
Set objACE = CreateObject(“AccessControlEntry”)
objACE.Trustee = strDomainNT4 & “” & objUser.Get(“sAMAccountName”)
wscript.echo objACE.Trustee
objACE.AccessMask = ADS_RIGHT_DS_WRITE_PROP
objACE.AceFlags = ADS_ACEFLAG_DONT_INHERIT_ACE
objACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE.Flags = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE.objectType = ADS_OBJECT_WRITE_MEMBERS
objDACL.AddAce(objACE)
end if
objSecurityDescriptor.DiscretionaryACL = objDACL
objGroup.Put “ntSecurityDescriptor”, Array(objSecurityDescriptor)
objGroup.SetInfo