Powershell - Get all email addresses from distibution groups a user is a member of

I have a Powershell script I run which allows me to enter a Active Directory User's name and retrieve the groups they are a member of. I then output that to a file that shows the Group name, and GroupCatagory. I need to add additional functionality to this script. I need to get the email address of any group the target user is a part of and add it as a column to the text file that is created. This is in an Exchange 2003 environment so I am trying to get the information from AD. My script is below. Can some recommend how to add that information to the text file the script generates?


$Destination = "$Env:userprofile\Desktop

Write-Host "Please enter the target user's Active directory username"

$Username = Read-Host

Get-ADPrincipalGroupMembership $Username | select name, GroupCategory > $Destination\"$Username.txt"
TechOps1Asked:
Who is Participating?

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

x
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.

CamyCommented:
Piping the group membership to Get-ADgroup will give you more information maybe;

$Destination = "$Env:userprofile\Desktop

Write-Host "Please enter the target user's Active directory username"

$Username = Read-Host

Get-ADPrincipalGroupMembership $Username | Get-ADGroup -properties mail | select name,mail,GroupCategory > $Destination\"$Username.txt"

Open in new window

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
TechOps1Author Commented:
Perfect. Thank you
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
Powershell

From novice to tech pro — start learning today.