Recently i was asked to list a: all members of an active directory group, and b: pull their primary email address, leaving me with an end report of username and primary email address.
I used dsget to pull the user information from the group, below is the command i used:
dsget group “cn=Groupname,ou=DLs,ou=Exchange Recipients,dc=ie,dc=domain,dc=company,dc=com” -members >> 1.txt
the above command enumerates the “groupname” group in an ou called dls, in an ou called exchange recipients in the domain ie.domain.company.com. if your ou or domain structure is different trim out (or add) what you need. The -members at the end of the file will dump only the usernames in FQDN format.
Once the script is run check the current directory for a textfile called 1.txt. This text file will contain the usernames you need in FQDN format like below:
“CN=Tom Thumb (IE),ou=Dublin,dc=ie,dc=domain,dc=company,dc=com”
“CN=Mike Hunt (IE),ou=Dublin,dc=ie,dc=domain,dc=company,dc=com”
In order to get the email address’es i decided not to try and read from the file, instead i just ran the same command again and piped the results to another dsget query.
dsget group “cn=Groupname,ou=DLs,ou=Exchange Recipients,dc=ie,dc=domain,dc=company,dc=com” -members | dsget user -email >> 2.txt
The above will pull the results we saw in 1.txt, but instead it passes it straight into another query (dsget user -email) and sends those results to a text file. 2.txt should contain the users primary email address:
tom.thumb@company.com
mike.hunt@company.ie
Now simply copy the contents on both text files into neighboring columns in excel and you have your report
Recent Comments