Solved

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

Posted on 2013-06-24
10
732 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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
 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

691 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