This morning a colleague wanted a way to export the members of a group and display certain properties of the user accounts. He was trying to use the Active Directory Administrative Center which was able to give him group members but not the extra attributes. Below is the command that I used to quickly get the information required. Note that this command will only export direct members. I’ll write a follow up post about recursing through sub groups to get all members.
I prefer to use the member attribute rather than the Get-ADGroupMember cmdlet as it tends to be a bit buggy. For example attempting to use Get-ADGroupMember on the group I use in my example resulted in this error: get-adgroupmember : The server was unable to process the request due to an internal error.
import-module ActiveDirectory;(get-adgroup [groupname] -properties member).member | get-aduser -properties [properties you want] | select name,[properties you want] | export-csv [file location] -notypeinformation
Replace the following sections:
[groupname] – name of the group you want to export the members of
[properties you want] – the properties you want to export
[file location] – the name and path of the csv file you want to export to
In the example below I wanted all members of the group Lync-ConferencingUsers and I wanted the attributes name, extensionAttribute5 and physicalDeliveryOfficeName (which in this organisation translates to name, company brand and location).
import-module ActiveDirectory;(get-adgroup Lync-ConferencingUsers -properties member).member | get-aduser -properties extensionAttribute5,physicalDeliveryOfficeName | select name,extensionAttribute5,physicalDeliveryOfficeName | export-csv H:lyncgroup.csv -notypeinformation