Introduction
This program checks or un-checks the "Manager can update membership list" check box for every group contained in the OU specified (if there's a manager assigned).
Background
I recently migrated a bunch of distribution groups from a child domain to its parent using the active directory migration tool. In the process, the check box permitting managers to modify groups members was cleared. Manually going in and opening every group, checking to see if it was managed and then checking the box was out of the question, so I began researching a way to script it. Using the code in a blog by Arnout van der Vorst found here, I was able to create this program.
Using the Code
This program Sets or Clears the "Manager can update members" check box for every group in the OU specified.
Usage Cscript MngChkBox.vbs Distinguished Name of OU <1 or 0>
Example 1
cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,ou=Sales 1
This will set the checkbox.
Example 2
cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,ou=Sales 0
This will clear it.
The Code
wscript.echo " "
wscript.echo " "
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}"
On Error Resume Next
DN = WScript.Arguments(0)
intEnabled = WScript.Arguments(1)
If (Wscript.Arguments.Count < 1) Then
Wscript.Echo "Program Name: MngChkBox.vbs"
WScript.Echo "Version: 1.2"
WScript.Echo "Purpose: Set or Clear the 'Manager can update members' _
check box for every group in the OU specified."
WScript.Echo "By Robert Kirchhof"
Wscript.Echo " "
WScript.Echo "Usage MngChkBox <1 or 0>"
Wscript.Echo
Wscript.Echo "cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,_
ou=Sales,dc=MyDomain,dc=com 1 will set the checkbox"
Wscript.Echo "cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,_
ou=Sales,dc=MyDomain,dc=com 0 will clear it."
Wscript.Echo
Wscript.Echo "Required argument is missing. " _
& "For example:" & vbCrLf _
& "cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,_
ou=Sales,dc=MyDomain,dc=com 1"
Wscript.Quit(0)
End If
If (Wscript.Arguments.Count < 2) Then
Wscript.Echo "Required argument <set> is missing. " _
& "For example:" & vbCrLf _
& "cscript MngChkBox.vbs ou=Distribution Groups,ou=Users & Groups,_
ou=Sales,dc=MyDomain,dc=com 0"
Wscript.Quit(0)
End If
Dim objRootDSE
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomainController = objRootDSE.Get("dnsHostName")
strDomain = objRootDSE.Get("defaultNamingContext")
strQuery = DN &","& strDomain
Set WshNetwork = WScript.CreateObject("WScript.Network")
strDomainNT4 = WshNetwork.UserDomain
Set objOU = GetObject("LDAP://" & strQuery )
objOU.Filter = Array("group")
Dim arrGroups
i = 0
For Each objUser in objOU
strLine=objUser.Name
Redim Preserve arrFileLines(i)
arrFileLines(i) = strLine
i = i + 1
Next
For Each strLine in arrFileLines
strCN=strLine
strGroup = strCN & "," & strQuery
Set objGroup = GetObject("LDAP://" & strDomainController & "/" & strGroup)
strManagedBy = objGroup.managedBy
If IsEmpty(strManagedBy) = FALSE Then
wscript.echo strCN & " is managed by " & strManagedBy
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)
wscript.echo objACE.Trustee & " Can NOT manage users in " & strCN
End If
Next
Else
Set objACE = CreateObject("AccessControlEntry")
objACE.Trustee = strDomainNT4 & "\" & objUser.Get("sAMAccountName")
wscript.echo objACE.Trustee & " Can now manage users in " & strCN
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
Else
wscript.echo strCN & " has no manager."
end If
WScript.Echo " "
Next
History
- 28th August, 2008: Initial post