Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass array collection to sub

Status
Not open for further replies.

bmquiroz

IS-IT--Management
Sep 26, 2003
207
US
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
 
strUsers = strUsers & " " & strName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Or simpler:
GetUser = Join(arrNames, " ")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hey PHV - Thanks that worked! Can you help me with one more thing? I’m trying to grab the "legacyExchangeDN" for each user as well. What I have below is only capturing the value for one user.

Thanks again!

Dim arrNames()
intSize = 0

Set objGroup = GetObject("LDAP://cn=Test,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
WScript.Echo "User: " & strName & " Exchange DN: " + objUser.Get("legacyExchangeDN")
Next
 
For Each strName In arrNames
Set objUser = GetObject("LDAP://" & strUser)
WScript.Echo "User: " & strName & " Exchange DN: " + objUser.Get("legacyExchangeDN")
Next



 
Oops, my bad - that won't work. Meant to preview that one!

Basically, you are only bound to the last userr in the array. You gotta rebind to each user, then do the objuser.get thing.
 
snOrg thanks for the reply but what changes do I need to make to get this output:

User: Some User
Exchange DN: /o=DOMAIN/ou=First Administrative Group/cn=Recipients/cn=someuser

The code below works but I would like to append the user's names as well.

Set objGroup = GetObject("LDAP://cn=Test,ou=Distribution,ou=Groups,ou=MMC,dc=mmc,dc=local")

For Each strUser In objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)

WScript.Echo " Exchange DN: " + objUser.Get("legacyExchangeDN")

Next

Thanks!
 
Nevermind. Got it working using the code below:

Dim arrNames()
intSize = 0

Set objGroup = GetObject("LDAP://cn=Test,ou=Distribution,ou=Groups,ou=DOMAIN,dc=domain,dc=local")

For Each strUser In objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
WScript.Echo "User: " & objUser.CN & " Exchange DN: " & objUser.Get("legacyExchangeDN")
Next

-Sip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top