PowerShell Script Add-EmailSuffix.ps1: Bulk Add Email Address Suffix in Exchange 2010

I recently had a need to bulk add email addresses to accounts in bulk.  I didn’t want to use Email Address Policies (for some non-related reason) so I decided to put together a handy PoSH script to add the addresses.

The Script has a few cool features:

  • Verifies the email address suffix is valid (including non-publicly routable addresses, i.e. domain.local).
  • Accepts input from the pipeline so you can filter the results of Get-Mailbox to quickly add the addresses.
  • Validates Email address has been added.
  • Output to screen.
  • Included help section.

Below is the source, or you can download Add-EmailSuffix.ps1


Adds email address suffix to mailbox based on Alias.
This script is intended to enable bulk addition of email addresses.
Version : 1.0 – 06/28/2012 – initial release
Rights Required : Recipient Admin in Exchange Org
Exchange Version : 2010
Author : Robert Durkin
Author Email : rdurkin@iccohio.com
Author Blog : http://ehloworld.net
Disclaimer : You running this script means you won’t blame me if this breaks your stuff.

.PARAMETER Mailboxes
The Identity parameter specifies the mailbox.
This parameter accepts the following values:
* Example: JPhilips
* Example: Atlanta.Corp.Contoso.Com/Users/JPhilips
* Example: Jeff Philips
* Example: CN=JPhilips,CN=Users,DC=Atlanta,DC=Corp,DC=contoso,DC=com
* Example: Atlanta\JPhilips
* Example: fb456636-fe7d-4d58-9d15-5af57d0354c2
* Example: fb456636-fe7d-4d58-9d15-5af57d0354c2@contoso.com
* Example: /o=Contoso/ou=AdministrativeGroup/cn=Recipients/cn=JPhilips
* Example: Jeff.Philips@contoso.com
* Example: JPhilips@contoso.com

.PARAMETER EmailSuffix
Valid email address suffix in the format of ‘@domain.suffix’

Get-Mailbox | .\Add-EmailSuffix.ps1 -EmailSuffix "@domain.com"
This would add the email address suffix @ohio.gov to all mailboxes.

.\Add-EmailSuffix.ps1 -Mailboxes "bob.durkin@domain.com" -EmailSuffix "@domain.com"
Add the email address suffix @domain.com to the mailbox with bob.durkin@domain.com.

Accepts pipline input for the Mailboxes parameter.
To Screen

#Requires -Version 2.0

# Parameters #

param([parameter(Mandatory=$True, ValueFromPipeline=$true, Position=0)][Object[]]$Mailboxes,
[parameter(Mandatory=$True, ValueFromPipeline=$false)][String]$EmailSuffix)

# Main #

begin {
#Regex to test email address. Does not check for internet routable compliance, by design.
$EmailAddressRegex = "@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"

process {

#Test for valid email address suffix format.
If (!($EmailSuffix -match $EmailAddressRegex)) {
Write-Host "Invalid Email Address Suffix. Please specify a valid address suffix (i.e. @domain.com)." -ForegroundColor Red

Foreach ($Mbx in $Mailboxes) {
[string]$NewAddress = $Mbx.Alias+$EmailSuffix
Write-Host "Adding $NewAddress to" $Mbx.Alias
Set-Mailbox $Mbx -EmailAddresses @{Add=$NewAddress}
If ((Get-Mailbox $Mbx).EmailAddresses | ?{$_.SmtpAddress -like "*$EmailSuffix"}) {
Write-Host "Verified that $NewAddress is a valid email address on $Mbx.Alias" -ForegroundColor Green
} Else {
Write-Host "Failed to add $NewAddress to $Mbx.Alias" -ForegroundColor Red

Preparing to Rebuild an Entire Exchange 2010 Organization

With the release of Exchange 2010 there has been some great advancement with high availability and site resiliency.  The traditional methods of disaster recovery are fading away.  Modern day high availability capabilities are introducing backup-less strategies.  Does that mean we don’t need to know how to get our messaging systems up and running in the event of a large scale major disaster….I think not?!

This thought process all got started when I was working to a recent effort to bring up a lab environment.  We didn’t have a lab in any way, but some systems were hosted on VMware’s hypervisor.  This included a couple Domain Controllers, but not any Exchange servers (mix of E2K7 & E2K10).  Creating a lab that mirrored production from scratch would be quite the undertaking, I mean, we were talking about some 14+ Exchange servers….not fun.  Well, to me, that scenario felt a lot like a disaster recovery situation and it got my wheels turning.  The use of Exchange’s recovery feature (setup.exe /m:RecoverServer) would allow me to leverage the directory (AD) that could be quickly cloned (thank you virtualization) to the lab.  After all, most Exchange configuration information is stored in Active Directory.  After building a few virtual machines for Exchange and I should be up and running.  I should mention that in this case, I don’t really care about the data, so the only material I really need is a Domain Controller and the Exchange installation media.

Read more

Checking Exchange 2010 for Open Relay Configuration

There is plenty of information on the web that instructs us how to configure Exchange 2010 (or 2007) to allow for relay of SMTP to external recipients (Open Relay). For example, Microsoft has posted these instructions.

However, I couldn’t easily find any information about how to check if this was already configured. This could be handy in verifying that a recent configuration was successful or with troubleshooting an open relay issue. The following PowerShell command checks all Receive Connectors on all Exchange servers (2007 & 2010) and returns any Receive Connectors that have been granted the ability to relay to external recipients.

[ps light=”1″]
Get-ReceiveConnector | get-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" | Where {$_.ExtendedRights -like "Ms-Exch-SMTP-Accept-Any-Recipient"}

Send-SMTP PowerShell Script

I’ve been creating scripts to automate administrative tasks for myself and clients. PowerShell scripts are a very nice way of accomplishing the needed automation when working with Exchange 2010.

One such task often involves gathering information for monitoring purposes. To facilitate the sharing of information it is always helpful to be able to send email.

I have been using this script for a while now that allows for just that. The code is below or you can download the .ps1 file: Send-SMTP.ps1. Enjoy!

Sends Email Message
Allows the generation and submission of a SMTP message to an MTA (email server).

Version : 1.0 – 04/26/2010 – initial version
Rights Req’d : Local Server Admin
Sch Task Req : No
Author : Robert Durkin
Email : rdurkin (at) ehloworld.net
Blog : http://ehloworld.net
Disclaimer : Don’t blame me if this breaks your stuff. Please don’t Spam!
References :
Online Version: http://ehloworld.net/?p=60
.\Send-SMTP.ps1 -From "sender@domain.net" -To "recipient@domain.net" -Subject "Blog Post" -Body "Ehlo World!" -Server mailer.domain.com


#Requires -Version 2.0

[Parameter(Mandatory = $True,valueFromPipeline=$True)][string] $From,
[Parameter(Mandatory = $True,valueFromPipeline=$True)][string] $To,
[Parameter(Mandatory = $True,valueFromPipeline=$True)][string] $Subject,
[Parameter(Mandatory = $True,valueFromPipeline=$True)][string] $Body,
[Parameter(Mandatory = $True,valueFromPipeline=$True)][string] $Server,
[Parameter(Mandatory = $false,valueFromPipeline=$True)] $File
) #end param

#Create Mailer Object and assign values
$MTA = New-Object Net.Mail.SMTPclient($Server)
$Msg = New-Object Net.Mail.MailMessage

$Msg.From = $From
$Msg.Subject = $Subject
$Msg.Body = $Body

#Attach File, if applicable
IF ($File -ne $Null)
$File = New-Object Net.Mail.Attachment($File)