Hi all,
The below procedure enumerates group membership and passes an array collection to the variable "strName". My problem is that when I try to pass "strName" outside the loop or function, it only returns one element of the variable i.e. one username. If I do a "WScript.Echo strName" within the For Each loop, I get the entire collection. How can I pass the entire array collection as a variable outside my function?
Thanks in advance.
-Sip
Function GetUser()
Dim arrNames()
intSize = 0
Set objGroup = GetObject("LDAP://cn=Test Users,ou=Distribution,ou=Groups,ou=DOMAIN,dc=domain,dc=local")
For Each strUser In objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
ReDim Preserve arrNames(intSize)
arrNames(intSize) = objUser.CN
intSize = intSize + 1
Next
For i = (UBound(arrNames) - 1) To 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1) = arrNames(j)
arrNames(j) = strHolder
End If
Next
Next
For Each strName In arrNames
strUsers = strName
Next
GetUser = strUsers
End Function
The below procedure enumerates group membership and passes an array collection to the variable "strName". My problem is that when I try to pass "strName" outside the loop or function, it only returns one element of the variable i.e. one username. If I do a "WScript.Echo strName" within the For Each loop, I get the entire collection. How can I pass the entire array collection as a variable outside my function?
Thanks in advance.
-Sip
Function GetUser()
Dim arrNames()
intSize = 0
Set objGroup = GetObject("LDAP://cn=Test Users,ou=Distribution,ou=Groups,ou=DOMAIN,dc=domain,dc=local")
For Each strUser In objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
ReDim Preserve arrNames(intSize)
arrNames(intSize) = objUser.CN
intSize = intSize + 1
Next
For i = (UBound(arrNames) - 1) To 0 Step -1
For j= 0 to i
If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
strHolder = arrNames(j+1)
arrNames(j+1) = arrNames(j)
arrNames(j) = strHolder
End If
Next
Next
For Each strName In arrNames
strUsers = strName
Next
GetUser = strUsers
End Function