Skip to content

Instantly share code, notes, and snippets.

@IAMPetro
Last active December 11, 2016 09:29
Show Gist options
  • Save IAMPetro/cec0043bc668ca0583f1e89aaa9c7e1e to your computer and use it in GitHub Desktop.
Save IAMPetro/cec0043bc668ca0583f1e89aaa9c7e1e to your computer and use it in GitHub Desktop.
Exchange: Add Email Aliases
function Add-BulkEmailAlias
{
<#
.Synopsis
This function will create the desired email aliases for the specified mailbox
.Example
C:\PS>Add-BulkEmailAlias -PrimaryEmailAddress your.mailbox@mydomain.com -AliasPrefix testAlias –Domain @mydomain.com -NumberOfAlias 1000
This example will create 1000 emails addressess called testAlias1@mydomain.com > testAlias1000@mydomain.com
and attaches them to the primary mailbox your.mailbox@mydomain.com
.Notes
Name: Add-BulkEmailAlias
Author: Petro Margaritis
Last Edit: 06/01/2015
Keywords: Mailbox, Email Alias, Exchange 2010, Add
.Link
http://www.iampetro.com/
#>
Param (
[parameter(Mandatory=$true)][string]$PrimaryEmailAddress,
[parameter(Mandatory=$true)][string]$AliasPrefix,
[parameter(Mandatory=$true)][string]$Domain,
[parameter(Mandatory=$true)][int]$NumberOfAlias
)
try
{
for ($i=1; $i -le $NumberOfAlias; $i++)
{
$aliasName = $AliasPrefix + $i + $Domain
Set-Mailbox $PrimaryEmailAddress -EmailAddresses @{Add=$aliasName}
Write-Host "The alias: "$aliasName", has been added to the account: "$PrimaryEmailAddress -foregroundcolor Yellow
}
Write-Host "All Aliases have now been added" -foregroundcolor Green
}
catch [System.Exception]
{
# Display error captured
Write-Host "Error caught " -foregroundcolor Red
Write-host $error[0] -foregroundcolor Red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment