header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Adding a second smtp address for a user
Last Post 07 Sep 2011 12:11 PM by Ekasare. 38 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Page 1 of 212 > >>
Author Messages
CatherineB-ITSupportUser is Offline
New Member
New Member
Posts:2

--
04 Sep 2008 04:17 AM

    <!--[if gte mso 9]> Normal 0 false false false EN-GB X-NONE X-NONE MicrosoftInternetExplorer4

    <!--[if gte mso 10]> I have to keep adding second (third and many more) smtp address to peoples mailboxes for testing purposes, ie:

    the user needs to register an email address to test something so I add test1@domain.com to his mailbox, then the week after he needs another 10 adding so test2, test3 etc etc. Currently I am manually going in and adding the smtp addresses using the EMC.

    My question is, can this be done via the PS? As exchange doesn’t show me what its done (like when you add a new mail box it displays the script for future reference) after its complete the task I don’t know. I haven’t been able to figure it out. I am a complete novice with PS as I tend to opt for the EMC to do tasks.

    Any help would be most appreciated

    Catherine

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    04 Sep 2008 04:39 AM
    $user = Get-Mailbox userName
    $user.emailAddresses+="test123@domain.com"
    Set-Mailbox $user -emailAddresses $user.emailAddresses

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    CatherineB-ITSupportUser is Offline
    New Member
    New Member
    Posts:2

    --
    04 Sep 2008 05:15 AM
    I am not sure what I put where for a user called Elaine Mooney for example with an email of emooney@domain.com it would be

    $user = Get-Mailbox EMooney
    $user.emailAddresses+="newsmtp@domain.com"
    Set-Mailbox $user -emailAddresses $user.emailAddresses < what do I put here?

    Please forgive me if it sounds a stupid question! Can i put multiple smtp addresses in at the same time?

    Catherine
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    04 Sep 2008 05:51 AM

    Hello;

    The first line, ($user = get-mailbox emooney) gets the mailbox.
    The second line, ($user.emailAddresses += "newsmtp@domain.com") adds the new mail address. Here, you would replace newwsmtp@domain.com with emooney$domain.com. The += in that line takes the existing emailaddresses, and adds the new one.
    The third line, (Set-Mailbox $user -emailAddresses $user.emailAddresses) puts the collection of addressses into the mailbox object.

    You can add more addresses by adding more lines like the second one, so:

    $user

    = Get-Mailbox EMooney

    $user

    .emailAddresses += "emooney@domain.com"

    $user

    .emailAddresses += "elaine.mooney@domain.com"

    $user

    .emailAddresses += "elainem@domain.com"

    Set-Mailbox

    $user -emailAddresses $user.emailAddresses

    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    apperraultUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    22 Sep 2008 10:51 AM

    I have a question about this script. My organization is going through a re-branding, and i I need to add a new email address for every user (and distribution list) in our organization, and set that email address as the default Outbound email address. This looks exactly like what i would need, the question i have is how to generate the email addresses for the script. we want everyone to have first.last@company.com, and firstInitialLastname@company.com. Normally i would use the recipient policy, but most of our users have the recipient policy enforcement disabled, since we have recently merged three different organizations, and some people have companyX email addresses, while others have CompanyZ, and others have CompanyA, so i need to script EVERYONE having the new email address.

    I am assuming i would do something like this:

    $user = Get-Mailbox *
    $user.emailaddress+="???????????????????????????" -->What do i put here for First.Last@company.com
    Set-Mailbox $user -emailaddresses $user.emailaddresses

    Then i would assume i would write a second script that would be:
    $user = Get-Mailbox *
    $user.emailaddress+="???????????????????????????" --> what do i put here for FirstInitialLastName@company.com

    and that would be it for the addition of the second one.

    Any thoughts would be greatly appreciated. We are launching our new brand tomorrow, so i need to get this down pat so i can run the script at 6:00am tomorrow morning when we launch

    Thanks much

    app

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    22 Sep 2008 11:50 AM
    Try this:

    Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {

    $user = Get-user $_.distinguishedName

    if(!$user.firstName -and !$user.lastName -and !$user.Initials){
    write-error "user information is not sufficient"
    break
    }

    $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com"
    $email2= "{0}.{1}{2}" -f $user.Initials[0],$user.lastName, "@company.com"

    $_.emailAddresses += ($email1,$email2)
    Set-Mailbox $_ -emailAddresses $_.emailAddresses
    }


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    apperraultUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    22 Sep 2008 12:04 PM

    Shay,

    Thanks for this, I will try it out in the AM.  One question, from that code, where is the set default mailbox, or is that the set-mailbox $_ -emailAddresses $_.emailAddresses command.

     

    I just want to make sure that i understand the syntax correctly.

     

    thanks

     

    app

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    22 Sep 2008 12:06 PM

    You mean the default email address? :

    # assuming the default will be the second address
    $primary = $email2

    # change the set-mailbox line to this
    Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    apperraultUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    22 Sep 2008 12:15 PM

    So, if you were going to do this, your script would read:

     

    Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {

    $user = Get-user $_.distinguishedName
    $primary = $email1

    if(!$user.firstName -and !$user.lastName -and !$user.Initials){
    write-error "user information is not sufficient"
    break
    }

    $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com"
    $email2= "{0}.{1}{2}" -f $user.Initials?],$user.lastName, "@company.com"

    $_.emailAddresses += ($email1,$email2)
    Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary

    }

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    22 Sep 2008 12:17 PM
    Yes, just move the line:

    $primary = $email1

    After the email1,email2 assignment:

    Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {

    $user = Get-user $_.distinguishedName

    if(!$user.firstName -and !$user.lastName -and !$user.Initials){
    write-error "user information is not sufficient"
    break
    }

    $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@company.com"
    $email2= "{0}.{1}{2}" -f $user.Initials?],$user.lastName, "@company.com"
    $primary = $email1

    $_.emailAddresses += ($email1,$email2)
    Set-Mailbox $_ -emailAddresses $_.emailAddresses -primarySmtpAddress $primary

    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    apperraultUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    22 Sep 2008 12:26 PM

    Thanks for the help.  I will report back in the AM how it went.

     

    app

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    22 Sep 2008 12:28 PM
    Don't go yet, I have some last minute changes, watch this thread in the next minutes. I'm working on it as we *spaek*

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    22 Sep 2008 12:32 PM

    There yo go


    1. Change all logical -and to -or
    2. You can't use both PrimarySMTPAddress and EmailAddresses parameters at the same time (error), so I'm adding a second call to set-mailbox

    Here's the last script version, it has been debugged and tested successfully.


    Get-Mailbox -filter "RecipientType -eq 'UserMailbox'" | foreach {

    $user = Get-user $_.DistinguishedName

    if(!$user.firstName -or !$user.lastName -or !$user.Initials){
    write-error "user information is not sufficient"
    break
    }

    $email1= "{0}.{1}{2}" -f $user.firstName,$user.lastName, "@companya.com"
    $email2= "{0}{1}{2}" -f $user.Initials[0],$user.lastName, "@companya.com"
    $primary = $email2

    $_.emailAddresses += ($email1,$email2)
    Set-Mailbox $_ -emailAddresses $_.emailAddresses
    Set-Mailbox $_ -primarySmtpAddress $primary -emailAddressPolicyEnabled $false

    }


    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    apperraultUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    22 Sep 2008 01:24 PM
    Thanks much.

    app
    sailingguyUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    11 Jun 2009 06:54 AM
    I'm trying to accomplish something very similar however I need to take current primary SMTP address and write it to the secondary "small" smtp location and take the input from my .csv file and put it in the primary SMTP attribute position. My script will take the input and overwrite the primary but I'm unable to figure out how to stamp the old address intothe smtp attribute.

    $list = Import-csv c:\Input.csv
    foreach ($entry in $list) {
    $newaddressstring = $entry.SMTP
    $User = $entry.username

    $oldaddress = get-mailbox -identity $user |select PrimarySmtpAddress
    set-mailbox -identity $user -PrimarySmtpAddress $newaddressstring -EmailAddressPolicyEnabled $false
    do{$address = get-mailbox -identity $user |select PrimarySmtpAddress}while ($address.PrimarySmtpAddress.ToString().ToLower() -ne $newaddressstring)
    $mailbox = Get-Mailbox -identity $user
    $mailbox.EmailAddresses -= $oldaddress.PrimarySmtpAddress.ToString()
    set-mailbox -identity $user -EmailAddresses $mailbox.EmailAddresses
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    11 Jun 2009 06:59 AM
    Sailingguy;

    See if this helps:

    http://powershellcommunity.org/Foru...fault.aspx
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Thiago Di GiorgioUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    09 Sep 2009 06:53 AM
    Hello Shay,

    I have modified your script a little bit to fit to my needs, but when I execute I get this error

    [PS] C:\>Get-mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach {
    >> $user = Get-user $_.Name
    >> $email1= $user,"@teste1.com"
    >> Set-User $_ -lastname $email1
    >> }
     >>
    Set-User : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LastName'. Specified method is not s upported. At line:4 char:22 + Set-User $_ -lastname <<<< $email1
    [PS] C:\>


    What can I do??

    Thanks!!!



    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    09 Sep 2009 07:00 AM
    $email1 is an array, it contains $user in the first element and "@teste1.com" in the second, try this:

    Get-mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach {
    $user = (Get-user $_.Name).Name
    $email1= "$user"@teste1.com"
    Set-User $_ -lastname $email1
    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Thiago Di GiorgioUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    09 Sep 2009 07:10 AM
    Shay, my needs is to add 2 others smtp addresses, but I need to get the name of the user to build the email address, I have modified your script like this and get this error see bellow the script and the results.

    Thanks!!!

    [PS] C:\>Get-Mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach {
    >> $user = (Get-user $_.Name).Name
    >> $email1= $user,"@teste.com"
    >> $email2= $user,"@teste1.com"
    >> $_.emailAddresses += ($email1,$email2)
    >> Set-Mailbox $_ -emailAddresses $_.emailAddresses
    >> }
    >>
    Exception setting "EmailAddresses": "Cannot convert value "System.Object[]" to type "Microsoft.Exchange.Data.ProxyAddressCollection
    ". Error: "Conversion from System.Object[] to Microsoft.Exchange.Data.ProxyAddress has not been implemented.""
    At line:5 char:4
    + $_.e <<<< mailAddresses += ($email1,$email2)
    [PS] C:\>
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    09 Sep 2009 07:13 AM
    You are still using a comma in the email address, that's bad. It turns the email address into an array. I aslo had a typo :), Try this:

    [PS] C:\>Get-Mailbox -Filter { CustomAttribute5 -eq "teste"} | foreach {
    $user = (Get-user $_.Name).Name
    $email1= "$user@teste.com"
    $email2= "$user@teste1.com"
    $_.emailAddresses += ($email1,$email2)
    Set-Mailbox $_ -emailAddresses $_.emailAddresses
    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Thiago Di GiorgioUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    09 Sep 2009 07:42 AM
    Shay, you have won a new fun.......

    It worked, THANK YOU SO MUCH......

    Sorry about my stupid mistakes....(this is my first doubt.....)

    I'm learning a lot now.....

    Thankssss

    =)
    Mr CoffeeUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    22 Nov 2009 11:14 PM
    Question about bulk import of x500 addresses for contacts using a CSV
    I am trying to add an X500 to a group of contacts using a CSV.
    I was using the mail attribute to pull the contacts up this is the first column of the csv then I have the x500 of legacyexchangeDN in the second column.
    I can use this to add an x500 to a group of users but when I attempt to do that to a group of contacts it does not work. I am struggling with even adding the x500 to the contacts at all via powershell.
    [PS] C:\PSscripts>import-csv UsersX500test.csv | foreach {
    >> $temp = Get-Contact -identity $_.mail
    >> $temp.ProxyAddresses += "x500:" + $_.legacyexchangedn
    >> Set-mailbox -instance $temp}>>

    I find that this works for user objects but not contacts.
    Can some one please tell me what I am doing wrong? Any help would be greatly appreciated.
    Mr CoffeeUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    22 Nov 2009 11:29 PM
    I think I was pulling contact and not mailcontact.

    I have not tested yet but I would bet that this fixes things for me.

    I will post back if that works.
    Mr CoffeeUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    23 Nov 2009 12:50 AM
    [PS] C:\PSscripts>import-csv UsersX500test.csv | foreach {
    >> $temp = Get-mailContact -identity $_.mail
    >> $temp.EmailAddresses += "x500:" + $_.legacyexchangedn
    >> Set-mailcontact -instance $temp}


    this is the script that I used to go from legacyexchangeDN to x500 works well when you have 2 forest that will eventually merge together I used a csv with mail attribute in 1st colum then legacy exchangeDN you could use alias but they are diffrent for these obejcts in the 2 forests.

    I hope it helps some one
    kepaUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    01 Dec 2009 10:43 PM
    Hi,

    I need to add secondary email address to users who have certain value in custom attribute 1. How to accomplish this with PowerShell? We have Exchange Server 2007.


    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    01 Dec 2009 10:48 PM
    PowerShell/Exchange version?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    kepaUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    01 Dec 2009 11:19 PM
    Posted By Shay on 01 Dec 2009 11:48 PM
    PowerShell/Exchange version?

    Exchange 2007 SP1/PowerShell 1.0.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Dec 2009 12:17 AM
    All mailboxes share the same value for custom attribute 1?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    kepaUser is Offline
    New Member
    New Member
    Posts:7
    Avatar

    --
    02 Dec 2009 12:25 AM
    Posted By Shay on 02 Dec 2009 01:17 AM
    All mailboxes share the same value for custom attribute 1?
    Yes.

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Dec 2009 12:48 AM
    Get-Mailbox -ResultSize Unlimited -Filter {CustomAttribute1 -eq "value"} | foreach { $_.EmailAddresses+= "foo1@domain.com"; $_} | Set-Mailbox

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    You are not authorized to post a reply.
    Page 1 of 212 > >>


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer