Export AD attributes from Distribution List

I have a need to export AD attributes such as Name, email, employee ID, phone#. location .... etc from a Distribution List. What's the best way to do this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Use the following command below to accomplish this.

$Users = Get-ADGroupMember -Identity <groupname>
ForEach ($User in $Users) {
Get-ADUser -Identity $User.sAMAccountName -Properties Name, mail, EmployeeID, OfficePhone,l | select Name, mail, EmployeeID, OfficePhone,l

Open in new window

That should do it.

If this is an exchange data, best way is ...
you could use powershell commandlets.
You could use vbscript.

A search for "retrieve information about distribution group members" will point to several options one of which refers to a competing site, but includes the following powershell cmdlet:
Get-DistributionGroup to get a list of distribution groups.

Get-DistributionGroup -identity "group of interest to you"
Get-DistributionGroupMember  is a cmdlet to list the members of a group.


I think the information you are looking for might not be where you think it is .
i.e. you might have to use the above to identify the users that are members of the distribution group and then pass them into a dsquery|dsget to extract the complete information.

I.e. not sure employee number is stored within the exchange section of the user schema. The phone number .........
Steve WhitcherSystems AdministratorCommented:
Using Powershell, either on a DC or a workstation with the RSAT tools installed:
import-module activedirectory
$Members = get-adgroupmember "GROUP NAME" - recursive
$Members | get-aduser -properties * | select -property Name,EmailAddress,EmployeeNumber,TelephoneNumber,Office

Open in new window

You can add or change the properties listed after the select statement to get exactly the info you want.

Edit: Oops, I guess I took too long and didn't refresh the page before posting.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

CiscoAznAuthor Commented:
This is not an AD group but an Email Distribution List that I need to export from.
Steve WhitcherSystems AdministratorCommented:
An AD group can be either "security" or "distribution" type, I assumed you meant a distribution group, which work like a sort of mailing list in exchange.  If that's not right, what sort of email distribution list are you talking about?
Will SzymkowskiSenior Solution ArchitectCommented:
I have modified my origainal script.
Import-Module activedirectory
$Users = GetDistributionGroupMember -Identity <groupname>
ForEach ($User in $Users) {
Get-ADUser -Identity $User.sAMAccountName -Properties Name, mail, EmployeeID, OfficePhone,l | select Name, mail, EmployeeID, OfficePhone,l

Open in new window

I also wanted to note that Get-DistributionGroupMember is part of the Exchange cmdlets. So you need to run this directly from the Exchange Mangement Shell.

If you are running it from a regular powershell session you need to add the appropriate snapin based on your Exchange Server Version.

CiscoAznAuthor Commented:
Will I tried your script and it didn't work. I tried Steve's script and it worked perfectly. Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.