Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Group object MEMBERS property confusion

Reply
 
Old 11-07-2008   #1 (permalink)
Tim Munro


 
 

Group object MEMBERS property confusion

Hello all,

I have a quick little script to simply tell me how many members I have
in all my groups. I am using the "MEMBERS" property. Now everywhere I've
read it says that the property is singular (MEMBER). This has never worked
for me, whereas the plural does work. Can anyone tell me (us?) what the real
story is here?

Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
Set RecordSet = CreateObject("ADODB.RecordSet")

oConnection.Open "Provider=ADsDSOObject"
oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 1000
oCommand.CommandText = DomainRootADSPath &
";(objectcategory=group);ADsPath;subtree"
Set RecordSet = oCommand.Execute

RecordSet.movefirst
wscript.stdout.writeline "Name,Count,Description"
While not RecordSet.EOF
sADsPath = RecordSet.Fields("ADsPath").Value
Set oGroup = GetObject(sADsPath)
sGroupname = UCase(oGroup.cn)
set colMembers = oGroup.members <====== This must be plural for it
to work, against all documentation I've read.
(even "The scripting guys" say this should be "member" and
not "members")
wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
oGroup.Description
RecordSet.movenext
Wend

Set oGroup = Nothing



My System SpecsSystem Spec
Old 11-07-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Group object MEMBERS property confusion

Tim Munro wrote:
Quote:

> I have a quick little script to simply tell me how many members I have
> in all my groups. I am using the "MEMBERS" property. Now everywhere I've
> read it says that the property is singular (MEMBER). This has never worked
> for me, whereas the plural does work. Can anyone tell me (us?) what the
> real story is here?
>
> Set oConnection = CreateObject("ADODB.Connection")
> Set oCommand = CreateObject("ADODB.Command")
> Set RecordSet = CreateObject("ADODB.RecordSet")
>
> oConnection.Open "Provider=ADsDSOObject"
> oCommand.ActiveConnection = oConnection
> oCommand.Properties("Page Size") = 1000
> oCommand.CommandText = DomainRootADSPath &
> ";(objectcategory=group);ADsPath;subtree"
> Set RecordSet = oCommand.Execute
>
> RecordSet.movefirst
> wscript.stdout.writeline "Name,Count,Description"
> While not RecordSet.EOF
> sADsPath = RecordSet.Fields("ADsPath").Value
> Set oGroup = GetObject(sADsPath)
> sGroupname = UCase(oGroup.cn)
> set colMembers = oGroup.members <====== This must be plural for it
> to work, against all documentation I've read.
> (even "The scripting guys" say this should be "member" and
> not "members")
> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
> oGroup.Description
> RecordSet.movenext
> Wend
>
> Set oGroup = Nothing
>
The "member" attribute of group objects is a multi-valued collection of
direct member DN's. The "Members" method of the group object is a function
that returns a collection of object references, one for each direct member
of the group. In your example you retrieve the AdsPath of each group, then
in the loop you bind to each group object (using the AdsPath) and invoke the
Members method to get an object reference to each member. That works,
although it involves binding to each group and member object, which can be
slow. Alternatively, you could retrieve the member attribute directly and
enumerate the multi-valued collection of DN's. Or, you can determine the
number of direct members. For example:
===========
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
Set RecordSet = CreateObject("ADODB.RecordSet")

oConnection.Open "Provider=ADsDSOObject"
oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 100
oCommand.CommandText = DomainRootADSPath _
& ";(objectcategory=group)" _
& ";cn,description,sAMAccountName,member;subtree"
Set RecordSet = oCommand.Execute

Wscript.Echo "Common Name,NetBIOS Name,description,count"
Do Until Recordset.EOF

strName = Recordset.Fields("sAMAccountName").Value

strCN = Recordset.Fields("cn").Value

strDesc = Recordset.Fields("description").Value

arrMembers = Recordset.Fields("member").Value

If IsNull(arrMembers) Then

lngCount = 0

ElseIf (TypeName(arrMembers) = "String") Then

lngCount = 1

Else

lngCount = UBound(arrMembers) + 1

End If

Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
CStr(lngCount)
Recordset.MoveNext
Loop



Recordset.Close

oConnection.Close

===========

Note there is no need to bind to the group objects to retrieve the values of
the cn, sAMAccountName, or description attributes. Just add them to the
comma delimited list of attribute values to retrieve. If you need more
information about the direct members, you may need to bind to those objects.
However, it is easy to display the DN of the members, or in this case, the
number of direct members of each group. The code just must account for the
possibility that the member attribute is empty (in which case ADO retrieves
a Null), has one value (in which case ADO retrieves the value as a String),
or more than one value (in which case ADO retrieves the values as an array).
The advantage here is that no AD objects need to be bound. This will be much
faster if there are many groups and members. Much of the work is done on the
DC in one shot.


--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 11-07-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Group object MEMBERS property confusion


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

> Tim Munro wrote:
>
Quote:

>> I have a quick little script to simply tell me how many members I have
>> in all my groups. I am using the "MEMBERS" property. Now everywhere I've
>> read it says that the property is singular (MEMBER). This has never
>> worked for me, whereas the plural does work. Can anyone tell me (us?)
>> what the real story is here?
>>
>> Set oConnection = CreateObject("ADODB.Connection")
>> Set oCommand = CreateObject("ADODB.Command")
>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>
>> oConnection.Open "Provider=ADsDSOObject"
>> oCommand.ActiveConnection = oConnection
>> oCommand.Properties("Page Size") = 1000
>> oCommand.CommandText = DomainRootADSPath &
>> ";(objectcategory=group);ADsPath;subtree"
>> Set RecordSet = oCommand.Execute
>>
>> RecordSet.movefirst
>> wscript.stdout.writeline "Name,Count,Description"
>> While not RecordSet.EOF
>> sADsPath = RecordSet.Fields("ADsPath").Value
>> Set oGroup = GetObject(sADsPath)
>> sGroupname = UCase(oGroup.cn)
>> set colMembers = oGroup.members <====== This must be plural for
>> it to work, against all documentation I've read.
>> (even "The scripting guys" say this should be "member" and
>> not "members")
>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>> oGroup.Description
>> RecordSet.movenext
>> Wend
>>
>> Set oGroup = Nothing
>>
>
> The "member" attribute of group objects is a multi-valued collection of
> direct member DN's. The "Members" method of the group object is a function
> that returns a collection of object references, one for each direct member
> of the group. In your example you retrieve the AdsPath of each group, then
> in the loop you bind to each group object (using the AdsPath) and invoke
> the Members method to get an object reference to each member. That works,
> although it involves binding to each group and member object, which can be
> slow. Alternatively, you could retrieve the member attribute directly and
> enumerate the multi-valued collection of DN's. Or, you can determine the
> number of direct members. For example:
> ===========
> Set oConnection = CreateObject("ADODB.Connection")
> Set oCommand = CreateObject("ADODB.Command")
> Set RecordSet = CreateObject("ADODB.RecordSet")
>
> oConnection.Open "Provider=ADsDSOObject"
> oCommand.ActiveConnection = oConnection
> oCommand.Properties("Page Size") = 100
> oCommand.CommandText = DomainRootADSPath _
> & ";(objectcategory=group)" _
> & ";cn,description,sAMAccountName,member;subtree"
> Set RecordSet = oCommand.Execute
>
> Wscript.Echo "Common Name,NetBIOS Name,description,count"
> Do Until Recordset.EOF
>
> strName = Recordset.Fields("sAMAccountName").Value
>
> strCN = Recordset.Fields("cn").Value
>
> strDesc = Recordset.Fields("description").Value
>
> arrMembers = Recordset.Fields("member").Value
>
> If IsNull(arrMembers) Then
>
> lngCount = 0
>
> ElseIf (TypeName(arrMembers) = "String") Then
>
> lngCount = 1
>
> Else
>
> lngCount = UBound(arrMembers) + 1
>
> End If
>
> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
> CStr(lngCount)
> Recordset.MoveNext
> Loop
>
>
>
> Recordset.Close
>
> oConnection.Close
>
> ===========
>
> Note there is no need to bind to the group objects to retrieve the values
> of the cn, sAMAccountName, or description attributes. Just add them to the
> comma delimited list of attribute values to retrieve. If you need more
> information about the direct members, you may need to bind to those
> objects. However, it is easy to display the DN of the members, or in this
> case, the number of direct members of each group. The code just must
> account for the possibility that the member attribute is empty (in which
> case ADO retrieves a Null), has one value (in which case ADO retrieves the
> value as a String), or more than one value (in which case ADO retrieves
> the values as an array). The advantage here is that no AD objects need to
> be bound. This will be much faster if there are many groups and members.
> Much of the work is done on the DC in one shot.
>
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>

Oops, I forgot that "description" is also multi-valued, although there is
never more than one value. This should work (in part):
============
Do Until Recordset.EOF
strName = Recordset.Fields("sAMAccountName").Value
strCN = Recordset.Fields("cn").Value
arrDesc = Recordset.Fields("description").Value
If IsNull(arrDesc) Then
strDesc = ""
Else
For Each strItem In arrDesc
strDesc = strItem
Next
End If
arrMembers = Recordset.Fields("member").Value
If IsNull(arrMembers) Then
lngCount = 0
ElseIf (TypeName(arrMembers) = "String") Then
lngCount = 1
Else
lngCount = UBound(arrMembers) + 1
End If
Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
CStr(lngCount)
Recordset.MoveNext
Loop

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 11-11-2008   #4 (permalink)
Tim Munro


 
 

Re: Group object MEMBERS property confusion

Thanks very much Richard. I'll play with some code to cement this in head.
--
Tim.

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

> Tim Munro wrote:
>
Quote:

>> I have a quick little script to simply tell me how many members I have
>> in all my groups. I am using the "MEMBERS" property. Now everywhere I've
>> read it says that the property is singular (MEMBER). This has never
>> worked for me, whereas the plural does work. Can anyone tell me (us?)
>> what the real story is here?
>>
>> Set oConnection = CreateObject("ADODB.Connection")
>> Set oCommand = CreateObject("ADODB.Command")
>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>
>> oConnection.Open "Provider=ADsDSOObject"
>> oCommand.ActiveConnection = oConnection
>> oCommand.Properties("Page Size") = 1000
>> oCommand.CommandText = DomainRootADSPath &
>> ";(objectcategory=group);ADsPath;subtree"
>> Set RecordSet = oCommand.Execute
>>
>> RecordSet.movefirst
>> wscript.stdout.writeline "Name,Count,Description"
>> While not RecordSet.EOF
>> sADsPath = RecordSet.Fields("ADsPath").Value
>> Set oGroup = GetObject(sADsPath)
>> sGroupname = UCase(oGroup.cn)
>> set colMembers = oGroup.members <====== This must be plural for
>> it to work, against all documentation I've read.
>> (even "The scripting guys" say this should be "member" and
>> not "members")
>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>> oGroup.Description
>> RecordSet.movenext
>> Wend
>>
>> Set oGroup = Nothing
>>
>
> The "member" attribute of group objects is a multi-valued collection of
> direct member DN's. The "Members" method of the group object is a function
> that returns a collection of object references, one for each direct member
> of the group. In your example you retrieve the AdsPath of each group, then
> in the loop you bind to each group object (using the AdsPath) and invoke
> the Members method to get an object reference to each member. That works,
> although it involves binding to each group and member object, which can be
> slow. Alternatively, you could retrieve the member attribute directly and
> enumerate the multi-valued collection of DN's. Or, you can determine the
> number of direct members. For example:
> ===========
> Set oConnection = CreateObject("ADODB.Connection")
> Set oCommand = CreateObject("ADODB.Command")
> Set RecordSet = CreateObject("ADODB.RecordSet")
>
> oConnection.Open "Provider=ADsDSOObject"
> oCommand.ActiveConnection = oConnection
> oCommand.Properties("Page Size") = 100
> oCommand.CommandText = DomainRootADSPath _
> & ";(objectcategory=group)" _
> & ";cn,description,sAMAccountName,member;subtree"
> Set RecordSet = oCommand.Execute
>
> Wscript.Echo "Common Name,NetBIOS Name,description,count"
> Do Until Recordset.EOF
>
> strName = Recordset.Fields("sAMAccountName").Value
>
> strCN = Recordset.Fields("cn").Value
>
> strDesc = Recordset.Fields("description").Value
>
> arrMembers = Recordset.Fields("member").Value
>
> If IsNull(arrMembers) Then
>
> lngCount = 0
>
> ElseIf (TypeName(arrMembers) = "String") Then
>
> lngCount = 1
>
> Else
>
> lngCount = UBound(arrMembers) + 1
>
> End If
>
> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
> CStr(lngCount)
> Recordset.MoveNext
> Loop
>
>
>
> Recordset.Close
>
> oConnection.Close
>
> ===========
>
> Note there is no need to bind to the group objects to retrieve the values
> of the cn, sAMAccountName, or description attributes. Just add them to the
> comma delimited list of attribute values to retrieve. If you need more
> information about the direct members, you may need to bind to those
> objects. However, it is easy to display the DN of the members, or in this
> case, the number of direct members of each group. The code just must
> account for the possibility that the member attribute is empty (in which
> case ADO retrieves a Null), has one value (in which case ADO retrieves the
> value as a String), or more than one value (in which case ADO retrieves
> the values as an array). The advantage here is that no AD objects need to
> be bound. This will be much faster if there are many groups and members.
> Much of the work is done on the DC in one shot.
>
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

My System SpecsSystem Spec
Old 11-11-2008   #5 (permalink)
Tim Munro


 
 

Re: Group object MEMBERS property confusion

In order to retrieve this property I would use the GetEX method?

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

> Tim Munro wrote:
>
Quote:

>> I have a quick little script to simply tell me how many members I have
>> in all my groups. I am using the "MEMBERS" property. Now everywhere I've
>> read it says that the property is singular (MEMBER). This has never
>> worked for me, whereas the plural does work. Can anyone tell me (us?)
>> what the real story is here?
>>
>> Set oConnection = CreateObject("ADODB.Connection")
>> Set oCommand = CreateObject("ADODB.Command")
>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>
>> oConnection.Open "Provider=ADsDSOObject"
>> oCommand.ActiveConnection = oConnection
>> oCommand.Properties("Page Size") = 1000
>> oCommand.CommandText = DomainRootADSPath &
>> ";(objectcategory=group);ADsPath;subtree"
>> Set RecordSet = oCommand.Execute
>>
>> RecordSet.movefirst
>> wscript.stdout.writeline "Name,Count,Description"
>> While not RecordSet.EOF
>> sADsPath = RecordSet.Fields("ADsPath").Value
>> Set oGroup = GetObject(sADsPath)
>> sGroupname = UCase(oGroup.cn)
>> set colMembers = oGroup.members <====== This must be plural for
>> it to work, against all documentation I've read.
>> (even "The scripting guys" say this should be "member" and
>> not "members")
>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>> oGroup.Description
>> RecordSet.movenext
>> Wend
>>
>> Set oGroup = Nothing
>>
>
> The "member" attribute of group objects is a multi-valued collection of
> direct member DN's. The "Members" method of the group object is a function
> that returns a collection of object references, one for each direct member
> of the group. In your example you retrieve the AdsPath of each group, then
> in the loop you bind to each group object (using the AdsPath) and invoke
> the Members method to get an object reference to each member. That works,
> although it involves binding to each group and member object, which can be
> slow. Alternatively, you could retrieve the member attribute directly and
> enumerate the multi-valued collection of DN's. Or, you can determine the
> number of direct members. For example:
> ===========
> Set oConnection = CreateObject("ADODB.Connection")
> Set oCommand = CreateObject("ADODB.Command")
> Set RecordSet = CreateObject("ADODB.RecordSet")
>
> oConnection.Open "Provider=ADsDSOObject"
> oCommand.ActiveConnection = oConnection
> oCommand.Properties("Page Size") = 100
> oCommand.CommandText = DomainRootADSPath _
> & ";(objectcategory=group)" _
> & ";cn,description,sAMAccountName,member;subtree"
> Set RecordSet = oCommand.Execute
>
> Wscript.Echo "Common Name,NetBIOS Name,description,count"
> Do Until Recordset.EOF
>
> strName = Recordset.Fields("sAMAccountName").Value
>
> strCN = Recordset.Fields("cn").Value
>
> strDesc = Recordset.Fields("description").Value
>
> arrMembers = Recordset.Fields("member").Value
>
> If IsNull(arrMembers) Then
>
> lngCount = 0
>
> ElseIf (TypeName(arrMembers) = "String") Then
>
> lngCount = 1
>
> Else
>
> lngCount = UBound(arrMembers) + 1
>
> End If
>
> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
> CStr(lngCount)
> Recordset.MoveNext
> Loop
>
>
>
> Recordset.Close
>
> oConnection.Close
>
> ===========
>
> Note there is no need to bind to the group objects to retrieve the values
> of the cn, sAMAccountName, or description attributes. Just add them to the
> comma delimited list of attribute values to retrieve. If you need more
> information about the direct members, you may need to bind to those
> objects. However, it is easy to display the DN of the members, or in this
> case, the number of direct members of each group. The code just must
> account for the possibility that the member attribute is empty (in which
> case ADO retrieves a Null), has one value (in which case ADO retrieves the
> value as a String), or more than one value (in which case ADO retrieves
> the values as an array). The advantage here is that no AD objects need to
> be bound. This will be much faster if there are many groups and members.
> Much of the work is done on the DC in one shot.
>
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

My System SpecsSystem Spec
Old 11-11-2008   #6 (permalink)
Richard Mueller [MVP]


 
 

Re: Group object MEMBERS property confusion

No need to use the GetEx method. The Members method automatically returns an
array of DN's. You can retrieve the member attribute like any other, but it
is multi-valued. You can use the Get method.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:OKHkMtCRJHA.2228@xxxxxx
Quote:

> In order to retrieve this property I would use the GetEX method?
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

>> Tim Munro wrote:
>>
Quote:

>>> I have a quick little script to simply tell me how many members I
>>> have in all my groups. I am using the "MEMBERS" property. Now everywhere
>>> I've read it says that the property is singular (MEMBER). This has never
>>> worked for me, whereas the plural does work. Can anyone tell me (us?)
>>> what the real story is here?
>>>
>>> Set oConnection = CreateObject("ADODB.Connection")
>>> Set oCommand = CreateObject("ADODB.Command")
>>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>>
>>> oConnection.Open "Provider=ADsDSOObject"
>>> oCommand.ActiveConnection = oConnection
>>> oCommand.Properties("Page Size") = 1000
>>> oCommand.CommandText = DomainRootADSPath &
>>> ";(objectcategory=group);ADsPath;subtree"
>>> Set RecordSet = oCommand.Execute
>>>
>>> RecordSet.movefirst
>>> wscript.stdout.writeline "Name,Count,Description"
>>> While not RecordSet.EOF
>>> sADsPath = RecordSet.Fields("ADsPath").Value
>>> Set oGroup = GetObject(sADsPath)
>>> sGroupname = UCase(oGroup.cn)
>>> set colMembers = oGroup.members <====== This must be plural for
>>> it to work, against all documentation I've read.
>>> (even "The scripting guys" say this should be "member" and
>>> not "members")
>>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>>> oGroup.Description
>>> RecordSet.movenext
>>> Wend
>>>
>>> Set oGroup = Nothing
>>>
>>
>> The "member" attribute of group objects is a multi-valued collection of
>> direct member DN's. The "Members" method of the group object is a
>> function that returns a collection of object references, one for each
>> direct member of the group. In your example you retrieve the AdsPath of
>> each group, then in the loop you bind to each group object (using the
>> AdsPath) and invoke the Members method to get an object reference to each
>> member. That works, although it involves binding to each group and member
>> object, which can be slow. Alternatively, you could retrieve the member
>> attribute directly and enumerate the multi-valued collection of DN's. Or,
>> you can determine the number of direct members. For example:
>> ===========
>> Set oConnection = CreateObject("ADODB.Connection")
>> Set oCommand = CreateObject("ADODB.Command")
>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>
>> oConnection.Open "Provider=ADsDSOObject"
>> oCommand.ActiveConnection = oConnection
>> oCommand.Properties("Page Size") = 100
>> oCommand.CommandText = DomainRootADSPath _
>> & ";(objectcategory=group)" _
>> & ";cn,description,sAMAccountName,member;subtree"
>> Set RecordSet = oCommand.Execute
>>
>> Wscript.Echo "Common Name,NetBIOS Name,description,count"
>> Do Until Recordset.EOF
>>
>> strName = Recordset.Fields("sAMAccountName").Value
>>
>> strCN = Recordset.Fields("cn").Value
>>
>> strDesc = Recordset.Fields("description").Value
>>
>> arrMembers = Recordset.Fields("member").Value
>>
>> If IsNull(arrMembers) Then
>>
>> lngCount = 0
>>
>> ElseIf (TypeName(arrMembers) = "String") Then
>>
>> lngCount = 1
>>
>> Else
>>
>> lngCount = UBound(arrMembers) + 1
>>
>> End If
>>
>> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
>> CStr(lngCount)
>> Recordset.MoveNext
>> Loop
>>
>>
>>
>> Recordset.Close
>>
>> oConnection.Close
>>
>> ===========
>>
>> Note there is no need to bind to the group objects to retrieve the values
>> of the cn, sAMAccountName, or description attributes. Just add them to
>> the comma delimited list of attribute values to retrieve. If you need
>> more information about the direct members, you may need to bind to those
>> objects. However, it is easy to display the DN of the members, or in this
>> case, the number of direct members of each group. The code just must
>> account for the possibility that the member attribute is empty (in which
>> case ADO retrieves a Null), has one value (in which case ADO retrieves
>> the value as a String), or more than one value (in which case ADO
>> retrieves the values as an array). The advantage here is that no AD
>> objects need to be bound. This will be much faster if there are many
>> groups and members. Much of the work is done on the DC in one shot.
>>
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>
>

My System SpecsSystem Spec
Old 11-11-2008   #7 (permalink)
Allan


 
 

Re: Group object MEMBERS property confusion

correct.. see here >
http://www.microsoft.com/technet/scr....mspx?mfr=true

object.Get("property") or object.GetEx("property") is different than doing
something like object.Name

Allan



"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:OKHkMtCRJHA.2228@xxxxxx
Quote:

> In order to retrieve this property I would use the GetEX method?
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

>> Tim Munro wrote:
>>
Quote:

>>> I have a quick little script to simply tell me how many members I
>>> have in all my groups. I am using the "MEMBERS" property. Now everywhere
>>> I've read it says that the property is singular (MEMBER). This has never
>>> worked for me, whereas the plural does work. Can anyone tell me (us?)
>>> what the real story is here?
>>>
>>> Set oConnection = CreateObject("ADODB.Connection")
>>> Set oCommand = CreateObject("ADODB.Command")
>>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>>
>>> oConnection.Open "Provider=ADsDSOObject"
>>> oCommand.ActiveConnection = oConnection
>>> oCommand.Properties("Page Size") = 1000
>>> oCommand.CommandText = DomainRootADSPath &
>>> ";(objectcategory=group);ADsPath;subtree"
>>> Set RecordSet = oCommand.Execute
>>>
>>> RecordSet.movefirst
>>> wscript.stdout.writeline "Name,Count,Description"
>>> While not RecordSet.EOF
>>> sADsPath = RecordSet.Fields("ADsPath").Value
>>> Set oGroup = GetObject(sADsPath)
>>> sGroupname = UCase(oGroup.cn)
>>> set colMembers = oGroup.members <====== This must be plural for
>>> it to work, against all documentation I've read.
>>> (even "The scripting guys" say this should be "member" and
>>> not "members")
>>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>>> oGroup.Description
>>> RecordSet.movenext
>>> Wend
>>>
>>> Set oGroup = Nothing
>>>
>>
>> The "member" attribute of group objects is a multi-valued collection of
>> direct member DN's. The "Members" method of the group object is a
>> function that returns a collection of object references, one for each
>> direct member of the group. In your example you retrieve the AdsPath of
>> each group, then in the loop you bind to each group object (using the
>> AdsPath) and invoke the Members method to get an object reference to each
>> member. That works, although it involves binding to each group and member
>> object, which can be slow. Alternatively, you could retrieve the member
>> attribute directly and enumerate the multi-valued collection of DN's. Or,
>> you can determine the number of direct members. For example:
>> ===========
>> Set oConnection = CreateObject("ADODB.Connection")
>> Set oCommand = CreateObject("ADODB.Command")
>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>
>> oConnection.Open "Provider=ADsDSOObject"
>> oCommand.ActiveConnection = oConnection
>> oCommand.Properties("Page Size") = 100
>> oCommand.CommandText = DomainRootADSPath _
>> & ";(objectcategory=group)" _
>> & ";cn,description,sAMAccountName,member;subtree"
>> Set RecordSet = oCommand.Execute
>>
>> Wscript.Echo "Common Name,NetBIOS Name,description,count"
>> Do Until Recordset.EOF
>>
>> strName = Recordset.Fields("sAMAccountName").Value
>>
>> strCN = Recordset.Fields("cn").Value
>>
>> strDesc = Recordset.Fields("description").Value
>>
>> arrMembers = Recordset.Fields("member").Value
>>
>> If IsNull(arrMembers) Then
>>
>> lngCount = 0
>>
>> ElseIf (TypeName(arrMembers) = "String") Then
>>
>> lngCount = 1
>>
>> Else
>>
>> lngCount = UBound(arrMembers) + 1
>>
>> End If
>>
>> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
>> CStr(lngCount)
>> Recordset.MoveNext
>> Loop
>>
>>
>>
>> Recordset.Close
>>
>> oConnection.Close
>>
>> ===========
>>
>> Note there is no need to bind to the group objects to retrieve the values
>> of the cn, sAMAccountName, or description attributes. Just add them to
>> the comma delimited list of attribute values to retrieve. If you need
>> more information about the direct members, you may need to bind to those
>> objects. However, it is easy to display the DN of the members, or in this
>> case, the number of direct members of each group. The code just must
>> account for the possibility that the member attribute is empty (in which
>> case ADO retrieves a Null), has one value (in which case ADO retrieves
>> the value as a String), or more than one value (in which case ADO
>> retrieves the values as an array). The advantage here is that no AD
>> objects need to be bound. This will be much faster if there are many
>> groups and members. Much of the work is done on the DC in one shot.
>>
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>
>
My System SpecsSystem Spec
Old 11-12-2008   #8 (permalink)
Tim Munro


 
 

Re: Group object MEMBERS property confusion

OK Thanks (gain) Richard. Now to look up the difference between "Get" and
"GetEx". The examples in the ScriptCentre show using GetEx.

(learning is fun (as long as it stays)).


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:Orj0QrHRJHA.4524@xxxxxx
Quote:

> No need to use the GetEx method. The Members method automatically returns
> an array of DN's. You can retrieve the member attribute like any other,
> but it is multi-valued. You can use the Get method.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Tim Munro" <Excelsior@xxxxxx> wrote in message
> news:OKHkMtCRJHA.2228@xxxxxx
Quote:

>> In order to retrieve this property I would use the GetEX method?
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
>> message news:uMT9RJSQJHA.2228@xxxxxx
Quote:

>>> Tim Munro wrote:
>>>
>>>> I have a quick little script to simply tell me how many members I
>>>> have in all my groups. I am using the "MEMBERS" property. Now
>>>> everywhere I've read it says that the property is singular (MEMBER).
>>>> This has never worked for me, whereas the plural does work. Can anyone
>>>> tell me (us?) what the real story is here?
>>>>
>>>> Set oConnection = CreateObject("ADODB.Connection")
>>>> Set oCommand = CreateObject("ADODB.Command")
>>>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>>>
>>>> oConnection.Open "Provider=ADsDSOObject"
>>>> oCommand.ActiveConnection = oConnection
>>>> oCommand.Properties("Page Size") = 1000
>>>> oCommand.CommandText = DomainRootADSPath &
>>>> ";(objectcategory=group);ADsPath;subtree"
>>>> Set RecordSet = oCommand.Execute
>>>>
>>>> RecordSet.movefirst
>>>> wscript.stdout.writeline "Name,Count,Description"
>>>> While not RecordSet.EOF
>>>> sADsPath = RecordSet.Fields("ADsPath").Value
>>>> Set oGroup = GetObject(sADsPath)
>>>> sGroupname = UCase(oGroup.cn)
>>>> set colMembers = oGroup.members <====== This must be plural for
>>>> it to work, against all documentation I've read.
>>>> (even "The scripting guys" say this should be "member"
>>>> and not "members")
>>>> wscript.stdout.writeline oGroup.cn & "," & colMembers.count & "," &
>>>> oGroup.Description
>>>> RecordSet.movenext
>>>> Wend
>>>>
>>>> Set oGroup = Nothing
>>>>
>>>
>>> The "member" attribute of group objects is a multi-valued collection of
>>> direct member DN's. The "Members" method of the group object is a
>>> function that returns a collection of object references, one for each
>>> direct member of the group. In your example you retrieve the AdsPath of
>>> each group, then in the loop you bind to each group object (using the
>>> AdsPath) and invoke the Members method to get an object reference to
>>> each member. That works, although it involves binding to each group and
>>> member object, which can be slow. Alternatively, you could retrieve the
>>> member attribute directly and enumerate the multi-valued collection of
>>> DN's. Or, you can determine the number of direct members. For example:
>>> ===========
>>> Set oConnection = CreateObject("ADODB.Connection")
>>> Set oCommand = CreateObject("ADODB.Command")
>>> Set RecordSet = CreateObject("ADODB.RecordSet")
>>>
>>> oConnection.Open "Provider=ADsDSOObject"
>>> oCommand.ActiveConnection = oConnection
>>> oCommand.Properties("Page Size") = 100
>>> oCommand.CommandText = DomainRootADSPath _
>>> & ";(objectcategory=group)" _
>>> & ";cn,description,sAMAccountName,member;subtree"
>>> Set RecordSet = oCommand.Execute
>>>
>>> Wscript.Echo "Common Name,NetBIOS Name,description,count"
>>> Do Until Recordset.EOF
>>>
>>> strName = Recordset.Fields("sAMAccountName").Value
>>>
>>> strCN = Recordset.Fields("cn").Value
>>>
>>> strDesc = Recordset.Fields("description").Value
>>>
>>> arrMembers = Recordset.Fields("member").Value
>>>
>>> If IsNull(arrMembers) Then
>>>
>>> lngCount = 0
>>>
>>> ElseIf (TypeName(arrMembers) = "String") Then
>>>
>>> lngCount = 1
>>>
>>> Else
>>>
>>> lngCount = UBound(arrMembers) + 1
>>>
>>> End If
>>>
>>> Wscript.Echo strCN & "," & strName & "," & strDesc & "," &
>>> CStr(lngCount)
>>> Recordset.MoveNext
>>> Loop
>>>
>>>
>>>
>>> Recordset.Close
>>>
>>> oConnection.Close
>>>
>>> ===========
>>>
>>> Note there is no need to bind to the group objects to retrieve the
>>> values of the cn, sAMAccountName, or description attributes. Just add
>>> them to the comma delimited list of attribute values to retrieve. If you
>>> need more information about the direct members, you may need to bind to
>>> those objects. However, it is easy to display the DN of the members, or
>>> in this case, the number of direct members of each group. The code just
>>> must account for the possibility that the member attribute is empty (in
>>> which case ADO retrieves a Null), has one value (in which case ADO
>>> retrieves the value as a String), or more than one value (in which case
>>> ADO retrieves the values as an array). The advantage here is that no AD
>>> objects need to be bound. This will be much faster if there are many
>>> groups and members. Much of the work is done on the DC in one shot.
>>>
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>>
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Remove members of the group. Members are from different domains PowerShell
Access to Interface's members of .NET object PowerShell
Can't access many IE object members PowerShell
to enumerate all the members of a object .NET General
[PS] Help exposing private members on object? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46