Solved

Exchange PowerShell:  Get all Primary and Alias SMTP Addresses of members of Distribution List

Posted on 2013-06-24
10
712 Views
Last Modified: 2013-07-24
I have a Distribution List and need the following information from the members of this distribution list:

AliasSMTPAddress PrimarySMTPAddress
AliasSMTPAddress PrimarySMTPAddress
AliasSMTPAddress PrimarySMTPAddress
AliasSMTPAddress PrimarySMTPAddress

e.g.
Frank@gmail.com Frank.Henry@gmail.com
Frank.h@gmail.com Frank.Henry@gmail.com
F.Henry@gmail.com Frank.Henry@gmail.com
Lara@gmail.com Lara.Chandler@gmail.com
Lara.C@gmail.com Lara.Chandler@gmail.com
L.Chandler@gmail.com Lara.Chandler@gmail.com

Open in new window

0
Comment
Question by:whenz
  • 6
  • 4
10 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39273119
Try this and see if it works as expected..
Get-DistributionGroupMember "GroupName" | Get-mailbox | % {
for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--)
{
 if ($_.EmailAddresses[$i].ProxyAddressString  -like “smtp:*” `
	-and $_.EmailAddresses[$i].ProxyAddressString -ne "SMTP:$($_.PrimarySmtpAddress.tostring())")
  {
  Add-Content C:\Group.txt "$($_.EmailAddresses[$i].ProxyAddressString) $($_.PrimarySmtpAddress.ToString())"
  }
 }
}

Open in new window

0
 

Author Comment

by:whenz
ID: 39326723
Hi Subsun

Sorry for my late reply.  The output looks fine with following expections:

1) The lines always begin with smtp:  Would it be possible to get an output without smtp: ?  

2) The script only works if user mailboxes are members of the DL.  But I also have DL's, contacts, public folders which are members of the DL.  Would it be possible to have a script which exports the aliases of these objects as well?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39327567
Get-DistributionGroupMember "GroupName"  | Get-Recipient | % {
for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--)
{
 if ($_.EmailAddresses[$i].ProxyAddressString  -like “smtp:*” `
	-and $_.EmailAddresses[$i].ProxyAddressString -ne "SMTP:$($_.PrimarySmtpAddress.tostring())")
  {
  Add-Content C:\Group.txt "$($_.EmailAddresses[$i].ProxyAddressString -Replace "^smtp:") $($_.PrimarySmtpAddress.ToString())"
  }
 }
}

Open in new window

Keep in mind the script will output the recipient which has a different alias address. If a recipient have only primary SMTP address then it wont display in the output (I presume that's what you looking for)
0
 

Author Comment

by:whenz
ID: 39332682
Thank you Subsun, your script works perfectly fine except that it does not read the aliases from public folders.  would that be possible?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39332882
It should read aliases from all recipients including public folders. As I mentioned above If a recipient have only primary SMTP address then it wont display in the output. Does your public folder have more than one email address?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:whenz
ID: 39332918
Hello Subsun,

You're right, was my mistake.  Our public folders only have 1 email address, the primary SMTP address.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39333418
So are we good? or do you want to add those addresses in report?
0
 

Author Comment

by:whenz
ID: 39333608
I would like to add the primary smtp addresses of public folders to the report.  that would be awesome!
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39333763
Check this code and see if the output format is as expected..
Get-DistributionGroupMember "GroupName"  | Get-Recipient | %{
$Primary = $_.PrimarySmtpAddress.ToString()

$_.EmailAddresses | ? {$_.SmtpAddress} | Select -Expandproperty SmtpAddress | % {
	If ($_ -ne $Primary) {
		Add-Content C:\Group.txt "$_ $Primary"
		}
	Else{
		Add-Content C:\Group.txt "$Primary"
		}
	}
}

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39333825
Or Try this.. Following code will display the email addresses in following format..
If there is only one email address for the recipient then it will write just PrimarySMTPAddress to the file else it will write..
AliasSMTPAddress PrimarySMTPAddress

Get-DistributionGroupMember "GroupName"  | Get-Recipient | %{
$Primary = $_.PrimarySmtpAddress.ToString()
$Email = $_.EmailAddresses | ? {$_.SmtpAddress}
	If (($Email | Measure).Count -gt 1) {
	 $Email | Select -Expandproperty SmtpAddress | % {
		If ($_ -ne $Primary) {
			Add-Content C:\Group.txt "$_ $Primary"
			}
		}
	}
	Else{
		Add-Content C:\Group.txt "$Primary"
	}
}

Open in new window

0

Featured Post

Why won’t your email signature format correctly?

Struggling to get your corporate email signatures to format correctly? Does the logo keep resizing? Is the text appearing too big? What can you do to prevent this? Find out how you can save your signatures today.

Question has a verified solution.

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

Suggested Solutions

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
A brief introduction to what I consider to be the best editor for PowerShell.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now