• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

Get list of computers in an active directory security group

I have a global security group in active directory that has computer members in it.  I want to export a list of them.  I used dsquery to do this from an OU but cannot find the right syntax to do it from a security group.  My current syntax is:

dsquery computer "?=security group,OU=Applications,ou=Groups,dc=ABC,dc=internal" -limit 0 -o rdn > c:\securitygroup_PCs.txt

What letters, instead of ?, go in front of =security group to indicate that it is a global security group and not an OU?

If it can't be done using dsquery, dsget or any other simple script will do.
  • 2
2 Solutions
Dsget should do the trick:
dsget group "CN=security group,OU=Applications,OU=Groups,DC=ABC,DC=internal" -members -expand > c:\securitygroup_PCs.txt

Open in new window

The "-expand" option will recurse any nested security groups and output the members from the nested security group too, omit it if that is not desirable.
BrianSDGAuthor Commented:
Thanks, it worked but I only want the computer names, not the whole CN.  How can I modify the command to just list the computer names?
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Try LDAP query such as below:

dsquery * -filter "(memberOf=cn=CompGroup,ou=West,dc=MyDomain,dc=local)" -attr sAMAccountName | find "$" /c
BrianSDGAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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