?
Solved

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

Posted on 2011-10-06
15
Medium Priority
?
851 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:malarkie
  • 6
  • 6
  • 3
15 Comments
 
LVL 7

Expert Comment

by:JohnGrunwell
ID: 36927057
power shell command should pull all the information for each member in the group

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

0
 
LVL 7

Expert Comment

by:JohnGrunwell
ID: 36927121
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"

0
 
LVL 49

Expert Comment

by:Akhater
ID: 36927137
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

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
LVL 7

Expert Comment

by:JohnGrunwell
ID: 36927149
To view the specific field names that you might want for exchange users
get-mailbox -identity "<domain\username>"  | fl
0
 

Author Comment

by:malarkie
ID: 36927998
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

0
 
LVL 49

Expert Comment

by:Akhater
ID: 36929962
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
0
 

Author Comment

by:malarkie
ID: 36931819
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.
0
 
LVL 49

Expert Comment

by:Akhater
ID: 36931962
sorry i dont know why i thoght u asked for the members :)

Use your script just add at the end > c:\t.txt
0
 
LVL 49

Expert Comment

by:Akhater
ID: 36932158
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
0
 

Author Comment

by:malarkie
ID: 36932267
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
0
 

Author Comment

by:malarkie
ID: 36932270
Just saw your post.  Let me check.
0
 

Author Comment

by:malarkie
ID: 36934259
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
0
 
LVL 49

Accepted Solution

by:
Akhater earned 2000 total points
ID: 36936421
This one


Get-DistributionGroup -resultSize unlimited | select name -expand emailAddresses | where {$_.smtpAddress} | Export-Csv c:\t.txt
0
 

Author Closing Comment

by:malarkie
ID: 36943705
That worked perfectly.  Thank you very much for your help, and with your patience.  I sincerly appreicate it.
0
 
LVL 49

Expert Comment

by:Akhater
ID: 36943730
You are welcome and thanks for the points
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question