We help IT Professionals succeed at work.

export exchange 2010 distribution list and members

lacroix_al
lacroix_al used Ask the Experts™
on
Hi
I have a 2010 exchange server and need to export a list of the distribution groups and the members.
so something like this

Group name 1
      member 1
      Member 2
      . . .
Group name 2
   . . .

I tryed using the
get-distributiongroup | get-distributiongroupmemebers

but of course it only gave me the memebers
how do I get a list as I want above?

Thank you
AL
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This will work:

$DLList = get-distributiongroup
foreach ($DL in $DLList){
write-host "Distribution Group: " $DL.name
get-distributiongroupmember -identity $DL.identity | ft name
write-host `n
}

Author

Commented:
Thank you for the reply

I tryed running this in powershell
It returned an error
unexpected token 'in'

What should I do to fix this?

Author

Commented:
Any reason I should be getting this error?
Not sure.  I just copied and pasted the code directly from EE website to a different lab of mine and it worked.  My guess is something got messed up in the "($DL in $DLList)" portion of the for each loop.  Maybe paste everything into notepad and make sure there's no unexpected characters.  You could then try copying and pasting each line one at a time to see where it fails.

Author

Commented:
ok
I see what I did wrong. once I pasted the code it returned a >> and I didn't realize I had to press enter again.
the code works as designed
the issue is this writes to the screen and I need it to write to a file.

Author

Commented:
ok
so I guess I wasn't clear in my first post.
I need the export to a file so I can print it out and make notes on it
it can be txt or CSV or whatever as long as it shows all the info I need.

Can you or someone else show me how to do this?

Thank you
AL

Author

Commented:
ok
so here is what I did.
I took the script above and modified it like this

$DLList = get-distributiongroup
foreach ($DL in $DLList){
get-distributiongroup -identity $DL.identity | Out-file "c:\groups\DLLIST.txt" -append
get-distributiongroupmember -identity $DL.identity | Out-file "c:\groups\DLLIST.txt" -append
}

this worked but I wanted to see if there was a better way to do it?

Thanks
Al
Sorry I didn't get back to you sooner.  work seems to be keeping me busy.  Anyway, yes, that's exactly what I would have recommended.

Author

Commented:
is there a way to dump it into excel
I tried using the |Export-Csv <file name>.csv
but I got an error

what should that look like?