Primary SMTP proxy address change

Welcome Forums General PowerShell Q&A Primary SMTP proxy address change

This topic contains 6 replies, has 2 voices, and was last updated by

 
Participant
1 year, 9 months ago.

  • Author
    Posts
  • #77185

    Participant
    Topics: 3
    Replies: 6
    Points: 14
    Rank: Member

    Hello everyone,

    I have such a complex task to acomplish(probably complex for me), basically we have one forest/domain that is syncing with O365.
    Primary SMTP address is not leading any specific format, for example first+lastname , for some users it is last+firstname
    We have to get all of the user SMTP addreses, that can be done easy; get-aduser -filter * -property * | where {$_.ProxyAddresses -clike "SMTP*@domain.name"}

    Question is, how we can preserve everything before @domain.name , so the user first+last or last+first name don't change, and change only domain name.

    Help will be greatly appreciated !

    Kind regards,
    Nemanja

  • #77191

    Participant
    Topics: 18
    Replies: 244
    Points: 108
    Rank: Participant

    Just to clarify a few things.
    1) Do you want the existing SMTP address preserved as a secondary address?
    2) The new SMTP address you want to be the same as the old one just with a new domain name?

    • #77197

      Participant
      Topics: 3
      Replies: 6
      Points: 14
      Rank: Member

      Hi,

      We don't want to add secondary SMTP address, we want to change the primary one, as you said, just to change domain while preserving everything behind @domain.name

      Kind regards,
      N

  • #77200

    Participant
    Topics: 18
    Replies: 244
    Points: 108
    Rank: Participant

    ok assuming you know how to get the users current smtp address to get the bit before the @ sysmbol you could use

    $local = $SMTP.local # Where $SMTP is the users SMTP Address

    with this you could create the new SMTP address
    $NewSMTP = $Local + "@" + $newdomainname

    Then using set-mailbox you will be able to set the new primary SMTP address

    • #77202

      Participant
      Topics: 3
      Replies: 6
      Points: 14
      Rank: Member

      This looks excellent, but I am still struggling to complete it, since I am not still really good with parsing informations, advise please if you have some tips 🙂

      So I did this for my user for example;

      $nemanja = Get-ADUser -Filter * -Properties * | Where-Object {$_.Name -like "nemanja.jovic"}

      After I call;

      $nemanja.proxyaddresses

      But it is coming with multiple SMTP and smtp addresses, how I can parse from here just SMTP for further script process?

      Thanks,
      N

  • #77205

    Participant
    Topics: 18
    Replies: 244
    Points: 108
    Rank: Participant

    try this

    Get-ADUser -Identity -Properties ProxyAddresses | Where-Object {$_.ProxyAddresses -cmatch "SMTP"}

    This should only bring back the primary address as it is case sensitive and onlt the primary will have SMTP in caps

  • #77296

    Participant
    Topics: 3
    Replies: 6
    Points: 14
    Rank: Member

    This is how I managed to complete this task;

    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
    Import-PSSession $Session
    Get-ADUser -SearchBase "OU=TEST,DC=DOMAIN,DC=GLOBAL" -Filter * -Properties * | Where-object {$_.ProxyAddresses -clike "SMTP:*@domain.global"} | Select-Object UserPrincipalName,SamAccountName | Export-Csv -Path C:\users.csv
    $userobjects = Import-Csv -Path C:\users.csv
    foreach ($user in $userobjects){
    $newdomain = "test.domain"
    $address = ((Get-Mailbox -Identity $user.UserPrincipalName).Primarysmtpaddress).toString()
    $Alias=$Address.Split("@")[0]
    $newsmtp="$alias@$newdomain"
    Set-ADUser -Identity $user.SamAccountName -Add @{proxyAddresses="SMTP:"+$newsmtp}
    Set-ADUser -Identity $user.SamAccountName -Remove @{proxyAddresses="SMTP:"+$address}
    }

The topic ‘Primary SMTP proxy address change’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort