Monday, July 30, 2012

powershell script to get a list of all members in a Security Group in a Windows 2008 R2 Domain


PS C:\Users\> get-adgroupmember "CN=testgroups,OU=Groups,OU=All Groups,DC=Contesso,DC=com,DC=au""  | get-aduser -properties cn,name,mail,enabled |select cn
,name,mail,enabled | export-csv C:\temp\pstest5.csv


This is the powershell version of the DSGet query posted earlier with output directed to a csv file.

DS Query to get a list of all users in a particular Security group in a Windows 2008 R2 Domain

dsget group "CN=testgroup,OU=groups,OU=all groups,DC=contesso,DC=com,DC=au" -members | dsget user -samid -display  -email -disabled > c:\temp\newquery.txt

This query allows you to extract the list of all user accounts with attributes UserId, Displayname , e-mail address and to check the status of the account [enabled/disabled] and write the result to a text file . This will be of help if the extracted list is greater than ~2000 entries.

I will come up with a power shell version soon.