[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2628
  • Last Modified:

VBScript - Object Not a Collection Error - How to test for single line collections?

Hi All,

I just wrote a vbscript code to lits the members of all groups in my AD unit. The code is pretty simple and its below, however, when it tries to list the members of a group with only one member, it hangs with the "Object Not a Collection" error.  Any hint on how to solve it? Thanks in advance!

Set objOU = GetObject("LDAP://ou=groups,ou=brazil,dc=amer,dc=mycompany,dc=com")
ObjOU.Filter= Array("group")
for each obj in objOU
      wscript.echo "Group Name: " &obj.name
      listMembers(obj.name)
      wscript.echo "-------------------------------------"
next

sub listMembers(strCN)
      set objGrupo = getobject("LDAP://" &strCN &",ou=groups,ou=brazil,dc=amer,dc=mycompany,dc=com")
      for each membro in objGrupo.member
            set objLogon = GetObject("LDAP://" &membro)
            wscript.echo objLogon.samAccountName
      next
end sub
0
rosado
Asked:
rosado
1 Solution
 
basicinstinctCommented:
That sounds weird to me, but I don't know anything about LDAP.

Do you still get the error if you do this?...


sub listMembers(strCN)
     set objGrupo = getobject("LDAP://" &strCN &",ou=groups,ou=brazil,dc=amer,dc=mycompany,dc=com")
     if not isNull(objGrupo) then
        for each membro in objGrupo.member
             set objLogon = GetObject("LDAP://" &membro)
             wscript.echo objLogon.samAccountName
        next
     end if
end sub
0
 
tone28Commented:
I have never had the problem of a group having on one user in it. But this is what I found.

Here is your code modified to check for a string typename knowing that only one user is in the group.

Let me know if this helps.

Set objOU = GetObject("LDAP://ou=groups,ou=brazil,dc=amer,dc=mycompany,dc=com")
ObjOU.Filter= Array("group")
for each obj in objOU
     wscript.echo "Group Name: " &obj.name
     listMembers(obj.name)
     wscript.echo "-------------------------------------"
next

sub listMembers(strCN)
    set objGrupo = getobject("LDAP://" &strCN &",ou=groups,dc=corp,dc=net")
    wscript.echo TypeName(objGrupo.member) & " " & VarType(objGrupo.member)
    If TypeName(objGrupo.member) = "String" Then
        wscript.echo objGrupo.member
        set objLogon = GetObject("LDAP://" & objGrupo.member)
        wscript.echo objLogon.samAccountName
    Else
        for each membro in objGrupo.member
            wscript.echo membro
            set objLogon = GetObject("LDAP://" & membro)
            wscript.echo objLogon.samAccountName
        
        next
    End If
end sub

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now