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 > PowerShell

Vista - Enumerating group membership & ADSI

Reply
 
Old 05-30-2007   #1 (permalink)
CrazyKiwi


 
 

Enumerating group membership & ADSI

Hi,

Can anyone tell me how to enumerate the members of an AD group using
Powershell?

It seems that the ADSI features are still quite limited so I'm wondering if
there is a quick way to do this.

Thanks in advance.

CrazyKiwi

My System SpecsSystem Spec
Old 05-30-2007   #2 (permalink)
RichS


 
 

RE: Enumerating group membership & ADSI

The easiest way to do it is if you can use the Quest AD cmdlets and use
Get-QADGroupMember from here
http://www.quest.com/activeroles-server/arms.aspx

if you need to do it with code then

$group = [ADSI] "LDAP://cn=Accounts,ou=AllGroups,dc=starking,dc=org"
foreach ($member in $group.member)
{
$member
}
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"CrazyKiwi" wrote:

> Hi,
>
> Can anyone tell me how to enumerate the members of an AD group using
> Powershell?
>
> It seems that the ADSI features are still quite limited so I'm wondering if
> there is a quick way to do this.
>
> Thanks in advance.
>
> CrazyKiwi

My System SpecsSystem Spec
Old 07-04-2007   #3 (permalink)
ColinH


 
 

RE: Enumerating group membership & ADSI

G'day,
Tried the suggested code however it only shows the first 1000 members. We
have some groups with much larger memberships. Any idea how to address this?

Thanks,

ColinH

"RichS" wrote:

> The easiest way to do it is if you can use the Quest AD cmdlets and use
> Get-QADGroupMember from here
> http://www.quest.com/activeroles-server/arms.aspx
>
> if you need to do it with code then
>
> $group = [ADSI] "LDAP://cn=Accounts,ou=AllGroups,dc=starking,dc=org"
> foreach ($member in $group.member)
> {
> $member
> }
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "CrazyKiwi" wrote:
>
> > Hi,
> >
> > Can anyone tell me how to enumerate the members of an AD group using
> > Powershell?
> >
> > It seems that the ADSI features are still quite limited so I'm wondering if
> > there is a quick way to do this.
> >
> > Thanks in advance.
> >
> > CrazyKiwi

My System SpecsSystem Spec
Old 07-04-2007   #4 (permalink)
Neil Chambers


 
 

Re: Enumerating group membership & ADSI

There may be other ways (using third party CmdLets) but the way I know
should work although does require another few lines of code

$group = [adsi]"LDAP://<yourDN>"
$groupSearcher = New-Object DirectoryServices.DirectorySearcher($group)
$groupSearcher.PageSize = 1000
$results = $groupSearcher.FindOne()
$results.properties.item("member")
<list of all members>

The issue is with the page size set on the Domain Controllers. It's
quite common to set it to 1000 to improve general query performance.
When that happens we have to adjust our code to be pagesize aware.

Hope that helps

n

On 2007-07-04 07:44:00 +0100, ColinH <ColinH@discussions.microsoft.com> said:

> G'day,
> Tried the suggested code however it only shows the first 1000 members.
> We have some groups with much larger memberships. Any idea how to
> address this?
>
> Thanks,
>
> ColinH
>
> "RichS" wrote:
>
>> The easiest way to do it is if you can use the Quest AD cmdlets and use
>> Get-QADGroupMember from here
>> http://www.quest.com/activeroles-server/arms.aspx
>>
>> if you need to do it with code then
>> $group = [ADSI] "LDAP://cn=Accounts,ou=AllGroups,dc=starking,dc=org"
>> foreach ($member in $group.member)
>> {
>> $member
>> }
>> --
>> Richard Siddaway
>> Please note that all scripts are supplied "as is" and with no warranty
>> Blog: http://richardsiddaway.spaces.live.com/
>> PowerShell User Group: http://www.get-psuguk.org.uk
>>
>>
>> "CrazyKiwi" wrote:
>>
>>> Hi,
>>>
>>> Can anyone tell me how to enumerate the members of an AD group using
>>> Powershell?
>>>
>>> It seems that the ADSI features are still quite limited so I'm
>>> wondering if there is a quick way to do this.
>>>
>>> Thanks in advance.
>>>
>>> CrazyKiwi



My System SpecsSystem Spec
Old 07-04-2007   #5 (permalink)
ColinH


 
 

Re: Enumerating group membership & ADSI

Neil,
Thanks for your reply however it didn't address the issue. When run the
property member = {} and instead the property member:range=0-999 contains the
first 1000 members {cn=..,cn=..,...}

$results.properties.item("member") produced no list
$results.properties.item("member;range=0-999") produced a list of 1000 members

Any ideas?
Regards,

ColinH

"Neil Chambers" wrote:

> There may be other ways (using third party CmdLets) but the way I know
> should work although does require another few lines of code
>
> $group = [adsi]"LDAP://<yourDN>"
> $groupSearcher = New-Object DirectoryServices.DirectorySearcher($group)
> $groupSearcher.PageSize = 1000
> $results = $groupSearcher.FindOne()
> $results.properties.item("member")
> <list of all members>
>
> The issue is with the page size set on the Domain Controllers. It's
> quite common to set it to 1000 to improve general query performance.
> When that happens we have to adjust our code to be pagesize aware.
>
> Hope that helps
>
> n
>
> On 2007-07-04 07:44:00 +0100, ColinH <ColinH@discussions.microsoft.com> said:
>
> > G'day,
> > Tried the suggested code however it only shows the first 1000 members.
> > We have some groups with much larger memberships. Any idea how to
> > address this?
> >
> > Thanks,
> >
> > ColinH
> >
> > "RichS" wrote:
> >
> >> The easiest way to do it is if you can use the Quest AD cmdlets and use
> >> Get-QADGroupMember from here
> >> http://www.quest.com/activeroles-server/arms.aspx
> >>
> >> if you need to do it with code then
> >> $group = [ADSI] "LDAP://cn=Accounts,ou=AllGroups,dc=starking,dc=org"
> >> foreach ($member in $group.member)
> >> {
> >> $member
> >> }
> >> --
> >> Richard Siddaway
> >> Please note that all scripts are supplied "as is" and with no warranty
> >> Blog: http://richardsiddaway.spaces.live.com/
> >> PowerShell User Group: http://www.get-psuguk.org.uk
> >>
> >>
> >> "CrazyKiwi" wrote:
> >>
> >>> Hi,
> >>>
> >>> Can anyone tell me how to enumerate the members of an AD group using
> >>> Powershell?
> >>>
> >>> It seems that the ADSI features are still quite limited so I'm
> >>> wondering if there is a quick way to do this.
> >>>
> >>> Thanks in advance.
> >>>
> >>> CrazyKiwi

>
>
>

My System SpecsSystem Spec
Old 07-05-2007   #6 (permalink)
Chris Warwick


 
 

Re: Enumerating group membership & ADSI

On Wed, 4 Jul 2007 19:40:00 -0700, ColinH
<ColinH@discussions.microsoft.com> wrote:

>Neil,
>Thanks for your reply however it didn't address the issue. When run the
>property member = {} and instead the property member:range=0-999 contains the
>first 1000 members {cn=..,cn=..,...}
>
>$results.properties.item("member") produced no list
>$results.properties.item("member;range=0-999") produced a list of 1000 members
>
>Any ideas?
>Regards,
>
>ColinH
>


Maybe take a look at the following pages:

Enumerating Groups That Contain Many Members
http://msdn2.microsoft.com/en-us/library/ms676302.aspx

Enumerating Members in a Large Group
http://msdn2.microsoft.com/en-us/library/ms180907.aspx

Searching Using Range Retrieval
http://msdn2.microsoft.com/en-us/library/aa367017.aspx

Attribute Range Retrieval
http://msdn2.microsoft.com/en-us/library/aa772308.aspx

HTH
Chris
My System SpecsSystem Spec
Old 07-05-2007   #7 (permalink)
to.mow@home.nl


 
 

Re: Enumerating group membership & ADSI

On 5 Jul, 10:01, Chris Warwick <n...@remove.this.bit.nuney.com> wrote:
> On Wed, 4 Jul 2007 19:40:00 -0700, ColinH
>
> <Col...@discussions.microsoft.com> wrote:
> >Neil,
> >Thanks for your reply however it didn't address the issue. When run the
> >property member = {} and instead the property member:range=0-999 contains the
> >first 1000 members {cn=..,cn=..,...}

>
> >$results.properties.item("member") produced no list
> >$results.properties.item("member;range=0-999") produced a list of 1000 members

>
> >Any ideas?
> >Regards,

>
> >ColinH

>
> Maybe take a look at the following pages:
>
> Enumerating Groups That Contain Many Membershttp://msdn2.microsoft.com/en-us/library/ms676302.aspx
>
> Enumerating Members in a Large Grouphttp://msdn2.microsoft.com/en-us/library/ms180907.aspx
>
> Searching Using Range Retrievalhttp://msdn2.microsoft.com/en-us/library/aa367017.aspx
>
> Attribute Range Retrievalhttp://msdn2.microsoft.com/en-us/library/aa772308.aspx
>
> HTH
> Chris


I have also some more information and examples in PowerShell on my old
blog here :

http://mow001.blogspot.com/2006/04/l...-in-monad.html

Greetings /\/\o\/\/
http://thePowerShellGuy.com

My System SpecsSystem Spec
Old 07-05-2007   #8 (permalink)
ColinH


 
 

Re: Enumerating group membership & ADSI

G'day,

Thanks to you both for your quick response. I used range retrieval to
return the results. I am using PowerShell to clean up a nasty four-way
x-domain / x-forest migration. Looking forward to the next PS release.

Regards,

ColinH

"to.mow@home.nl" wrote:

> On 5 Jul, 10:01, Chris Warwick <n...@remove.this.bit.nuney.com> wrote:
> > On Wed, 4 Jul 2007 19:40:00 -0700, ColinH
> >
> > <Col...@discussions.microsoft.com> wrote:
> > >Neil,
> > >Thanks for your reply however it didn't address the issue. When run the
> > >property member = {} and instead the property member:range=0-999 contains the
> > >first 1000 members {cn=..,cn=..,...}

> >
> > >$results.properties.item("member") produced no list
> > >$results.properties.item("member;range=0-999") produced a list of 1000 members

> >
> > >Any ideas?
> > >Regards,

> >
> > >ColinH

> >
> > Maybe take a look at the following pages:
> >
> > Enumerating Groups That Contain Many Membershttp://msdn2.microsoft.com/en-us/library/ms676302.aspx
> >
> > Enumerating Members in a Large Grouphttp://msdn2.microsoft.com/en-us/library/ms180907.aspx
> >
> > Searching Using Range Retrievalhttp://msdn2.microsoft.com/en-us/library/aa367017.aspx
> >
> > Attribute Range Retrievalhttp://msdn2.microsoft.com/en-us/library/aa772308.aspx
> >
> > HTH
> > Chris

>
> I have also some more information and examples in PowerShell on my old
> blog here :
>
> http://mow001.blogspot.com/2006/04/l...-in-monad.html
>
> Greetings /\/\o\/\/
> http://thePowerShellGuy.com
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
ADSI: Making an Explicit Call to GetInfoEx and Enumerating Results VB Script
Enumerating user's universal groups membership from ANOTHER DOMAIN VB Script
Enumerating user's universal groups membership from ANOTHER DOMAIN VB Script
ADSI and group membership - what am I doing wrong PowerShell
Enumerating local group membership with Powershell 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