Avatar of malarkie
malarkieFlag for United States of America

asked on 

Export Exchange 2007 Distribution Group and All Associate SMTP Addresses to CSV

I am trying to find a way to pull a list of all my Distribution Groups, and all their assoicate SMTP addresses and export them to .csv.  I have found a couple of powershell scripts that get me close, however I haven't gotten there completely.  Does anyone have any suggestions?
PowershellExchangeShell Scripting

Avatar of undefined
Last Comment
Akhater
Avatar of JohnGrunwell
JohnGrunwell
Flag of United States of America image

power shell command should pull all the information for each member in the group

Get-DistributionGroupMember "<Group Name>" | Export-CSV -Path "<FileName>"

Avatar of JohnGrunwell
JohnGrunwell
Flag of United States of America image

if you want all groups with certain fields like display name and smtp only you can use this in powershell

Get-DistributionGroup | %{
  $Group = $_
  $Group | Get-DistributionGroupMember |
    Select-Object @{n='GroupName';e={ $Group.Name }}, DisplayName, PrimarySMTPaddress
} | Export-CSV "filename location"

Avatar of Akhater
Akhater
Flag of Lebanon image

here you go
$gprs = Get-DistributionGroup -ResultSize unlimited

$grps | %{$n = $_.name; Get-DistributionGroupMember $_} | Select-Object name,@{label="Group";expression={$n}} | export-csv c:\list.csv

Open in new window

Avatar of JohnGrunwell
JohnGrunwell
Flag of United States of America image

To view the specific field names that you might want for exchange users
get-mailbox -identity "<domain\username>"  | fl
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

John & Akhater,
I tried your suggestions, howeve the resultant set only gives me Distro list and Members email addresses.  I need to get the Distro lists, as well as the Distro lists associated email addresses.  So for example, I have a Support Distro list that when someone emails either support@xyz.com or supportIT@xyz.com or help@xyz.com, when I run this powershell script it should give me;
Support, Support@xyz.com, SupportIT@xyz.com, help@xyz.com.  I found the following, however I want it to export it rather than write it to the screen, however my lack of understanding of coding leaves me drawing a blank.
Get-DistributionGroup | select name , alias ,EmailAddresses | foreach {
   “Name: “+$_.name
   “Alias: “+$_.alias
    $_.EmailAddresses | foreach {
      if($_.SmtpAddress){
      “SmtpAddress: “+$_.SmtpAddress
    }
 }
 write-host
 }

Open in new window

Avatar of Akhater
Akhater
Flag of Lebanon image

You lost me, you wanted to groups members now you are looking for the aliases of the groups?

Get-DistributionGroup -resultSize unlimited | select name -expand emailAddresses | where {$_.smtpAddress} | Export-Csv c:\t.txt
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

I don't believe I ever said I needed the group members, but it is an added benefit I received from this post.  I have saved all of these scripts as I can definitely see the benefit of what you all have posted so far.  But yes, the aliases of the group.  
The script you gave me doesn't return all the aliases for each group, just the first.  

Thanks again, I do appreciate your help.
Avatar of Akhater
Akhater
Flag of Lebanon image

sorry i dont know why i thoght u asked for the members :)

Use your script just add at the end > c:\t.txt
Avatar of Akhater
Akhater
Flag of Lebanon image

and sorry my script doesn't export only the first alias it exports them , check the csv you will see multiple entries for the same group each one for an smtp address
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

Getting closer.  I put that right after the "Write Host" and I get a blank document.  If I take out the "Write Host", I get

The term '>' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included,
 verify that the path is correct and try again.
At C:\BC_Scripts\DistributionList.ps1:9 char:3
+  > <<<< c:\at.csv
    + CategoryInfo          : ObjectNotFound: (>:String) [], CommandNotFoundEx
   ception
    + FullyQualifiedErrorId : CommandNotFoundException
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

Just saw your post.  Let me check.
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

sorry, I thought I ran yours earlier, however I just ran your script and received the following;

Get-DistributionGroupMember : Cannot bind argument to parameter 'Identity' beca
use it is null.
At line:1 char:52
+ $grps | %{$n = $_.name; Get-DistributionGroupMember <<<<  $_} | Select-Object
 name,@{label="Group";expression={$n}} | export-csv c:\list3.csv
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember],
   ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.Exchange.Management.RecipientTasks.GetDistributionGroupMember
ASKER CERTIFIED SOLUTION
Avatar of Akhater
Akhater
Flag of Lebanon image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of malarkie
malarkie
Flag of United States of America image

ASKER

That worked perfectly.  Thank you very much for your help, and with your patience.  I sincerly appreicate it.
Avatar of Akhater
Akhater
Flag of Lebanon image

You are welcome and thanks for the points
Exchange
Exchange

Exchange is the server side of a collaborative application product that is part of the Microsoft Server infrastructure. Exchange's major features include email, calendaring, contacts and tasks, support for mobile and web-based access to information, and support for data storage.

213K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo