Set oObject = GetObject("LDAP://ad2008rd/cn=Users,DC=soap,DC=com")
oObject.Filter= Array("Group")
ReDim arrGroups(1)
ReDim arrGroupMembers(1)
Dim oGroup,fileName,groupName,arrGroupMembersCounter,emptyGroupsCounter,groupsCounter
arrGroupMembersCounter=0
emptyGroupsCounter=0
groupsCounter=0
For Each oGroup in oObject
dim members
members=0
groupName = oGroup.cn
ReDim preserve arrGroups(groupsCounter+1)
groupPath = getgrouppath(groupName)
if groupPath = "" then
wscript.echo "Unable to find the specified group in the domain"
else
set objGroup = getobject(grouppath)
for each objMember in objGroup.Members
members=members+1
if arrGroupMembers(arrGroupMembersCounter) = "" then
arrGroupMembers(arrGroupMembersCounter) = objmember.samaccountname
else
arrGroupMembers(arrGroupMembersCounter) = arrGroupMembers(arrGroupMembersCounter) & "," & objmember.samaccountname
end if
next
getprimarygroupmembers groupname
wscript.echo groupName & ":"
if arrGroupMembers(arrGroupMembersCounter) = "" then
emptyGroupsCounter=emptyGroupsCounter+1
wscript.echo "EMPTY GROUP..."
else
arrGroups(groupsCounter)=groupName
groupsCounter=groupsCounter+1
wscript.echo "Number of Members: " & members
wscript.echo arrGroupMembers(arrGroupMembersCounter)
arrGroupMembersCounter=arrGroupMembersCounter+1
ReDim preserve arrGroupMembers(arrGroupMembersCounter+1)
end if
wscript.echo ""
end if
Next
wscript.echo "Number of groups: " & groupsCounter
wscript.echo "Number of empty groups: " & emptyGroupsCounter
findDuplicateGroups()
wscript.echo "Completed"
function findDuplicateGroups()
wscript.echo ""
wscript.echo "find duplicate groups members:"
for i = 0 to ubound(arrGroups)
for j = 0 to ubound(arrGroups)
if i<>j then
if arrGroupMembers(i) = arrGroupMembers(j) then
wscript.echo arrGroups(i) & " and " & arrGroups(j) & " has the same members:"
wscript.echo arrGroupMembers(j)
wscript.echo ""
end if
end if
next
next
end function
function getGroupPath(byval GroupName)
set cmd=createobject("ADODB.Command")
set cn=createobject("ADODB.Connection")
set rs=createobject("ADODB.Recordset")
cn.open "Provider=ADsDSOObject;"
cmd.commandtext = "SELECT adspath from 'LDAP://" & getnc & _
"' WHERE objectCategory = 'Group' and sAMAccountName = '" & groupname & "'"
cmd.activeconnection = cn
set rs = cmd.execute
if rs.bof <> true and rs.eof<>true then
getgrouppath=rs(0)
else
getgrouppath = ""
end if
cn.close
end function
function getNC
set objRoot=getobject("LDAP://RootDSE")
getNC=objRoot.get("defaultNamingContext")
end function
function getPrimaryGroupMembers(byval GroupName)
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rs = createobject("ADODB.Recordset")
cn.open "Provider=ADsDSOObject;"
cmd.activeconnection=cn
cmd.properties("page size")=1000
cmd.commandtext = "SELECT PrimaryGroupToken FROM 'LDAP://" & getnc & _
"' WHERE sAMAccountName = '" & GroupName & "'"
set rs = cmd.execute
if rs.eof<>true and rs.bof<>true then
PrimaryGroupID = rs(0)
else
Err.Raise 5000, "getPrimaryGroupMembers", "Unable to find PrimaryGroupToken property"
end if
cmd.commandtext = "SELECT samaccountname, sn, givenName FROM 'LDAP://" & getNC & _
"' WHERE PrimaryGroupID = '" & PrimaryGroupID & "'"
set rs = cmd.execute
while rs.eof<>true and rs.bof<>true
if arrGroupMembers(arrGroupMembersCounter) = "" then
arrGroupMembers(arrGroupMembersCounter) = rs("samaccountname")
else
arrGroupMembers(arrGroupMembersCounter) = arrGroupMembers(arrGroupMembersCounter) & "," & rs("samaccountname")
end if
rs.movenext
wend
cn.close
end function
|