Last active
December 11, 2016 09:31
-
-
Save IAMPetro/ecc5722c551395525b90c9284317895e to your computer and use it in GitHub Desktop.
Exchange: Remove Email Aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-BulkEmailAlias | |
{ | |
<# | |
.Synopsis | |
This function will create the desired email aliases for the specified mailbox | |
.Example | |
C:\PS>Remove-BulkEmailAlias -PrimaryEmailAddress your.mailbox@mydomain.com -AliasPrefix testAlias –Domain @mydomain.com -NumberOfAlias 1000 | |
This example will remove 1000 emails aliases called testAlias1@mydomain.com > testAlias1000@mydomain.com | |
from the primary mailbox your.mailbox@mydomain.com | |
.Notes | |
Name: Remove-BulkEmailAlias | |
Author: Petro Margaritis | |
Last Edit: 06/01/2015 | |
Keywords: Mailbox, Email Alias, Exchange 2010, Remove, Delete | |
.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 @{Remove=$aliasName} | |
Write-Host "The alias: "$aliasName", has been removed to the account: "$PrimaryEmailAddress -foregroundcolor Yellow | |
} | |
Write-Host "All requested Aliases have been removed" -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