header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How to change primary smtp addresses of entire organisation
Last Post 14 May 2012 08:48 AM by mike crowley. 16 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
NoIsEkIlLeRUser is Offline
New Member
New Member
Posts:49
Avatar

--
29 Jul 2009 09:10 AM
    Hi!

    I'm pretty new at this, but if anyone can help me it would be great!

    Where I'm working there is 1500 users in the AD, most of them with smtp addresses.

    We have a bug that we can't seem to fix, but maybe with a script we could bypass this problem.

    The thing actually is that everytime we create a new user and a new mailbox, the first two letters of the smtp address are typed automatically uppercase...

    Example:
    User name: test
    User's address : TEst@test.com

    This is not a big problem, but it would be easier for everyone (so nobody asks stupid questions) if all the addresses would change lowercase automatically...

    Any ideas?

    Thanks!
    AythUser is Offline
    Basic Member
    Basic Member
    Posts:237
    Avatar

    --
    29 Jul 2009 09:09 AM
    Try this(assumes exchange 2007):

    $users = Get-Mailbox | Select-Object primarysmtpaddress,identity

    foreach ($user in $users)
    {
    [string]$email = $user.Primiarysmtpaddress
    $email = $email.ToLower()
    Set-Mailbox -identity $user.identity -primarysmtpaddress $email
    }

    It could probably be done with less code, but I made it longer so it's easier to understand what is happening. If you have questions let me know. Thanks.
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    AythUser is Offline
    Basic Member
    Basic Member
    Posts:237
    Avatar

    --
    29 Jul 2009 09:18 AM
    LOL, thanks noisekiller, I was poking around the site and saw your post(was subscribed as well). Here's hoping it works, and I don't look like a fool :)
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    NoIsEkIlLeRUser is Offline
    New Member
    New Member
    Posts:49
    Avatar

    --
    29 Jul 2009 09:21 AM

    WHAT! YOU'RE SO FAST! ;)

    Thanks a lot, I'll be submiting this idea here this afternoon and test, I'll come back with the results as soon as I get them!

     

    Thanks again!

    NoIsEkIlLeRUser is Offline
    New Member
    New Member
    Posts:49
    Avatar

    --
    29 Jul 2009 10:38 AM

    I tried it and it returned me warnings saying that the object wasn't modified...but I think I know why...this might help us get the script working...!

    In the User's properties, if the SMTP address is TEst@test.com, Exchange won't change it even if I write manually test@test.com so I tried something : changed TEst@test.com for 1test@test.com and then changed it to test@test.com and everything works fine...it seems like Exchange won't change the property if the only thing changing is upper or lowercase...

    Is there a way to change the script so it adds a caracter at the end of the address like test1@test.com and then removes it?

    Thanks again!

    AythUser is Offline
    Basic Member
    Basic Member
    Posts:237
    Avatar

    --
    29 Jul 2009 11:47 AM
    Ok, based on that theory(great work by the way):

    $users = Get-Mailbox | Select-Object primarysmtpaddress,identity

    foreach ($user in $users)
    {
    [string]$email = $user.Primiarysmtpaddress
    $email = $email.ToLower()
    echo $email

    $tempemail = "1"+$email
    echo $tempemail

    Set-Mailbox -identity $user.identity -primarysmtpaddress $tempemail
    Start-Sleep 5
    Set-Mailbox -identity $user.identity -primarysmtpaddress $email
    }

    The echo's are basically there for testing, remove them if it's cumbersome. That will basically take their current email address prefix it with a numberic 1 set that as primary address, then set it back.
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    NoIsEkIlLeRUser is Offline
    New Member
    New Member
    Posts:49
    Avatar

    --
    29 Jul 2009 11:54 AM

    ALRIGHT!!!

    Thanks a lot!

    I'll try that later, maybe only tomorrow though!

    But thanks for your precious help, now I really owe a beer! :P

    I'll try to figure out how to use the script only on users that have uppercase smtp addresses, instead of all the organization.

     

    THANKS!

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

    --
    29 Jul 2009 01:11 PM
    You should check your e-mail address recipient policy. The upper case letters may be a part of your policy email name convention pattern and the email address of each user may change back next time the policy apply. Bear in mind that even if the script runs and fixes the issue then the next time the policy is applied the values will revert back.
    To prevent a policy from applying to users you can turn it off using the EmailAddressPolicyEnabled parameter (i.e. –EmailAddressPolicyEnabled:$false)

    Check this article for more information on Managing E-Mail Address Policies in Exchange Server 2007
    http://www.msexchange.org/articles_...icies.html


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

    --
    30 Jul 2009 06:44 AM

    Thanks for your input!

    Everytime that someone creates a user in our organization, this person unchecks the box that says "automatically updates with the addresses strategies" or something like that (sorry...I work in a french environnement". So when the policy is updated, it's not applied to anyone.

    BUT! I tried this moning in our pre-production environment and I disabled the organization's default policy to see if the first two letters are still uppercase...and NO! MAGIC! ;)

    So, I deleted the policy and created a new one, with the exact same properties and only one change in the name of the policy itself, just to be sure nothing is still linked to the old one and BOUM! No more uppercase!

    YAHOO!

    So now I just have to make a list of the users that might still have the famous checkbox checked, uncheck them and recreate the policy!

    Thanks a lot to everyone!

    NoIsEkIlLeRUser is Offline
    New Member
    New Member
    Posts:49
    Avatar

    --
    30 Jul 2009 11:05 AM

    I've overlooked something in my procedure...

    The organization's policy is to:

    Take the first letter of the first name and the complete last name...so...when we create a user, the name is John Smith, so the system creates JSmith@test.com instead of jsmith@test.com ...

    So I guess I'll have to run the script every once in a while so everyone has a lowercase email address in the organization...

    Any idea of what I could do instead of that?

    BUT! Take note that we are ALL in localized french OS and EXCHANGE...might be the problem?

    Thanks!

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

    --
    31 Jul 2009 07:30 AM
    Your policy is configured to take the first name initial and last name from the user's ad attributes so you would have to lowercase these attributes :(

    I'll try to dig in some more, maybe there's a workaround.

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

    --
    31 Jul 2009 08:28 AM

    Thanks a lot!

    If you find something that could work, you'll be my first hero (The Joker will be 2nd!) :)

    THANKS AGAIN!

    NoIsEkIlLeRUser is Offline
    New Member
    New Member
    Posts:49
    Avatar

    --
    03 Aug 2009 06:59 AM
    Posted By Shay on 31 Jul 2009 08:30 AM
    Your policy is configured to take the first name initial and last name from the user's ad attributes so you would have to lowercase these attributes :(

    I'll try to dig in some more, maybe there's a workaround.


    Found something yet? :(
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    04 Aug 2009 01:48 AM
    Nope, I asked a Microsoft PFE and he confirmed what I suggested to you, the only way (without changing the user first/last name ad attributes) is to disable address policy on the object (–EmailAddressPolicyEnabled:$false).

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

    --
    04 Aug 2009 05:00 AM

    Alright, thanks!

    Look at this, then I'll explain my problem with that script...!

    Get-QADUser -Enabled:$true -IncludedProperties msExchMailboxGuid, showInAddressBook | `
     Where-Object { (($_.msExchMailboxGuid -ne $null) -and ($_.showInAddressBook -ne $null)) } | ` ForEach-Object
    { Get-Mailbox -Identity $_.DN -resultsize unlimited | `
    Where-Object {($_.primarysmtpaddress -cmatch "[A-Z]")} | `
     Select-Object identity, primarysmtpaddress | `
    ForEach-Object
    { $user = $_
    [string]$email = $user.PrimarySmtpAddress
    $email = $email.ToLower()
    echo $email
    $tempemail = "1"+$email
    echo $tempemail
    Set-Mailbox -identity $user.identity -primarysmtpaddress $tempemail
    Start-Sleep 5
    Set-Mailbox -identity $user.identity -primarysmtpaddress $email
    echo $email
    }
    }

    When I run the script, it selects in AD only the users with an exchange mailbox, that are activated and have uppercase letters in their email address.

    The only problem I've got is that PowerShell doesn't modify the existing address, it creates a new PrimarySMTPAddress, with the "1" at the beginning, and then puts the old address (which still has uppercase letters) as the PrimarySMTPAddress...

    What should I do? Delete the address and create a new one?

    Thank you!

    ismail aksuUser is Offline
    New Member
    New Member
    Posts:8
    Avatar

    --
    18 May 2010 01:01 AM
    Hi

    How to remove smtp address in mailcontact on powershell

    Thanks already
    mike crowleyUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    14 May 2012 08:48 AM
    I came up with a similar script to the one posted by @ayth (I wish I had seen this post yesterday), but this lowercases all addresses, in addition to the primary. Not necessary for email to the internet, but might clean things up if people look in the GAL.

    http://mikecrowley.wordpress.com/20...lowercase/
    You are not authorized to post a reply.


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