Techibee.com

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.

Exit mobile version