Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-06-24
10
Medium Priority
?
756 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 2000 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

Lessons on Wi-Fi & Recommendations on KRACK

Simplicity and security can be a difficult  balance for any business to tackle. Join us on December 6th for a look at your company's biggest security gap. We will also address the most recent attack, "KRACK" and provide recommendations on how to secure your Wi-Fi network today!

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This video discusses moving either the default database or any database to a new volume.

963 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