On several occasions at work I have been asked to add email aliases to distribution groups for testing purposes. Depending on how many you have to add, in my case 30 or more, doing this through the exchange systems manager just won’t do. I mean, what self respecting systems engineer is going to copy and paste all these addresses one by one? Not me…did that the first time in a crunch and not doing it again.
Anyway, since there is a need for multiple email addresses we usually identify each by using a basic format followed by a number increment (user1, user2, user3 and so on and so forth). Since the aliases all have the same email address prefix I figured this was ripe for some powershell scripting so without further ado here is what I came up with.
#gets the distribution group name and puts it in a variable
$group = get-distributiongroup “example_group“
#enter starting number here
$i = 1
#enter email prefix
$user = “user“
#email domain address
$addr = “@yourdomain.com“
#This is the loop. It will continue adding addresses until the ending number is reached.
do {
$newaddr = $user+$i+$addr
$group.emailaddresses += $newaddr
set-distributiongroup -Identity $group -EmailAddresses $group.emailaddresses
$i +=1
}
#enter ending number in place of “40″
while ($i -le 40)
The above example will create email aliases for the distribution group called “example_group” starting with “user1@yourdomain.com” and ending with “user40@yourdomain.com”. If you wanted to increment another number just change the starting and ending numbers in the script.