Home > PowerShell > PowerShell: Query Active Directory group members using native cmdlets

PowerShell: Query Active Directory group members using native cmdlets

PowerShell has a native module called “ActiveDirectory” using which we can query active directory. The advantage of using this is, you no need to depend on external installers like Quest PowerShell tools to query active directory. The only pre-requisites for using the cmdlets in ActiveDirectory module is you should run these from either vista or windows 7 computer and you environment should have atleast one Windows 2008 R2 DC(or should have ADWS installed on windows 2003 DCs).

So, here is the code to query active directory group for its members.

Import-Module ActiveDirectory
Get-ADGroupMember -Identity Group1 | select Name, ObjectClass

In the above code I am first importing ActiveDirectory module and the using Get-ADGroupMember cmdlet to query the group named Group1 

If the Group1 has some more groups inside it, you can query the group recursively using the -recurse parameter.

ActiveDirectory some other useful cmdlets which you can use to manage group membership of Groups. For example, Add-ADGroupMember cmdlet helps us in adding a object to a group in AD. Similarly using Remove-ADGroupMeber we can remove objects from a group.

Categories: PowerShell Tags: ,
  1. Joe
    December 27, 2011 at 7:36 pm | #1

    Get-QADGroupMember is not native, it’s a Quest thing.
    This command is not recognized on a 2008R2 DC in a 2008 Domain.

    • December 27, 2011 at 10:41 pm | #2

      That is correct. Get-QADGroupMember belongs to Quest AD Powershell Snapin. But what I have used here in this post is, a native cmdlet(Get-ADGroupMember) that comes along with activedirectory module which is available in windows 2008 and windows 7. Just wondering why you referred that.

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>