Adding new mail Adresses to a mail account
Hey Guys! I'm very green on Exchange but I tried the shell and I couln't leave it anymore!! You can do A LOT! from there and best of all you can Script it so you can use it later! so heres the thing: I need to add new addresses to an E-mail Account to enable it to Send/receive external mailing. Is there a way to copy ONLY the account name and changing the 'at' part? Example: take the 'johndoe' from 'johndoe@anywhere.com' and generate this 3 new addresses: 'johndoe@anything.com' 'johndoe@anyhow.com' 'johndoe@anyone.com' Regards! PS: I'm also looking for a good basic tutorial about Exchange shell, If anyone knows.... Thanks in advance!
November 9th, 2010 2:11pm

Something like this? $newaddrs = @() $a = "johndoe@anywhere.com" $newaddrs += $a $newaddrs += $a.split("@")[0] + "@anything.com" $newaddrs += $a.split("@")[0] + "@anyhow.com" $newaddrs += $a.split("@")[0] + "@anyone.com" $newaddrs johndoe@anywhere.com johndoe@anything.com johndoe@anyhow.com johndoe@anyone.com[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 9th, 2010 3:16pm

Hi, In addition to mjolinor said, If you want to Send/receive external mails, you need to add accepted domains. For example(the mailbox is johndoe, and it e-mail address is johndoe@anywhere): If you want to add an email address johndoe@anything.com to the account, you can follow these steps to achieve the goal: 1. Add a accepted domain “anything .com”. New-AcceptedDomain -Name "anything" -DomainName anything.com -DomainType Authoritative 2. You can follow this way to copy only the account name and changing the ‘at’ part: $newaddrs=@() $addrs= “ johndoe@anywhere.com” $newaddrs += $addrs.split("@")[0] + "@anything.com" 3. Add a new Email address to the account: $foo =get-mailbox johndoe $foo.EmailAddresses += $newaddrs $foo | set-mailbox 4. Then you can use the new Email address to receive the emails, if you want use the new Email address to send emails, you can set the e-mail address to the primary e-mail address: Set-EmailAddressPolicy -Identity "Default Policy" -EnabledEmailAddressTemplates SMTP:@anything.com,smtp:@anywhere.com Update-EmailAddressPolicy -Identity "Default Policy" Here is a related article for you: How to Configure Exchange 2007 to Accept E-Mail for More Than One Authoritative Domain http://technet.microsoft.com/en-us/library/aa996314(EXCHG.80).aspx If anything is unclear, please feel free to let me know and I will be glad to help. Best Regards, Evan
November 15th, 2010 12:35am

2. You can follow this way to copy only the account name and changing the ‘at’ part: $newaddrs=@() $addrs= “ johndoe@anywhere.com” $newaddrs += $addrs.split("@")[0] + "@anything.com" Hey!! Everything was very clarifing thank you!! I want to let this thing built with a little more of automation in it :) So I was thinking if it's there a way to Run the script and then prompt the user for the -Id of the mailbox you want to add more mailboxes. I was trying to do it by leaving the cmdlet without parameters (something like: '$a = Get-Mailbox -Id ') but no luck :S... How can I do it? Thanks again guys you were very helpful! Regards
Free Windows Admin Tool Kit Click here and download it now
November 15th, 2010 11:44am

Have a look at the read-host cmdlet: $user = read-host "Enter a user name" if (get-mailbox $user){ <set addresses> } Else {Write-host "Sorry, I cannot find a mailbox for that user."}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 15th, 2010 11:52am

Ok, What I tought to do is something like this: $newaddrs = @() --> What does this do? $userid = read-host "ID?" --> I'm trying to get this data from the user $a = get-mailbox -id $userid --> and then put the infoon a Variable $newaddrs --> Here is the Adding the 'at' part :) $newaddrs1 += $a.split("@")[0] + "@bcba.com.ar" Can't totally comprehend how this instruction works $newaddrs2 += $a.split("@")[0] + "@e-bcba.com.ar" does it takes the '@' like a separator? and the [0]? $newaddrs3 += $a.split("@")[0] + "@bancociudad.com.ar" --< $a.EmailAddresses += $newaddrs1 --> Now I'm Adding the new Addresses to the account $a.EmailAddresses += $newaddrs2 $a.EmailAddresses += $newaddrs3 $a | set-mailbox Half of it doesn't run and the other half don't know what it does (or how to do it) XD XD please read the comments on the lines :) Thanks Again!
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 10:43am

$newaddrs = @() This initializes a new, empty array. We need to do this because we're going to be adding addresses to it, and the way string additon works in Powershell. Do this: $newaddrs += "user@domain1.com" $newaddrs += "user@domain2.com" $newaddrs and you get: user@domain1.comuser@domain2.com Do this: $newaddrs = @() $newaddrs += "user@domain1.com" $newaddrs += "user@domain2.com" $newaddrs and you get: user@domain1.com user@domain2.com As for the rest of it, the first bit of code was based on a premise that you wanted to add new secondary addressed, given the primary address of the user: $a = "user@domain.com" The split method splits the string at the character provided in the argument ("@"). This give you an array of two elements ([0] and [1]) - the user part and the host part of the address. $a.split("@")[0] user $a.split("@")[1] domain.com Since we're replacing the domain part, we only care about the user part ([0]). It's not working because in the first example, $a was assumed to be the primarysmtpaddress. In the construted script, it's the malibox object. So: $newaddrs = @() $userid = read-host "ID?" $a = get-mailbox -id $userid $usr = $a.primarysmtpaddress.tostring().split("@")[0] $newaddrs = @() $newaddrs += $usr + "@bcba.com.ar" $newaddrs += $usr + "@e-bcba.com.ar" $newaddrs += $usr + "@bancociudad.com.ar" $a.EmailAddresses += $newaddrs $a | set-mailbox[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 19th, 2010 11:12am

It works just perfect!! thank you all guys! One more thing... How do I "Set as Reply" one of the added address (something like Set (last written address) as primarysmtpaddress) Can it be something like this? Set-mailbox -primarysmtpaddress $newaddrs[3] (the [3] is the array position where the address is located)
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 12:41pm

FWIW, you can also get the user part of a an email address object with (get-user <username>).primaryemailaddress.local the domain part is available as (get-user <username>).primaryemailaddress.domain [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 19th, 2010 1:05pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics