Solved

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

Posted on 2013-06-24
10
717 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this video we show how to create an Accepted Domain 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 >> Ac…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

803 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