Skip to content

techbloggingfool.com

  • Home
  • Gear
  • Microsoft
  • Linux
  • Apple
  • Networking
  • Gaming
  • Digital Notes
  • The Buzz
  • About
  • Contact

Tag: Script Email Addresses

PowerShell; Build Azure AD Connect Email Addresses without a local Exchange Server

August 20, 2019Posted in MicrosoftTagged Automate Office 365 Email Addresses, Exchange On-line Addresses, Office 365 address policy, Office 365 email address policy, Office 365 Migration, PowerShell Email Addresses, Script Email AddressesLeave a comment

Not long ago I needed to change a company’s email address format from first initial last name@company.com (flast@company.com) to first name.last name@company.com (first.last@company.com). There were several hundred user accounts in the on-premises Active Directory. The local AD was being synchronized to Office 365 with Azure AD Connect.

Typically, an environment like this might have a stripped-down Exchange server configured for a hybrid federation with Office 365 to get access to the ECP (Exchange Control Panel). Having the ECP would have allowed me to use an address policy to solve this dilemma. However, this environment did not have such an option. Their available compute resources prevented the creation of a Exchange management server, so another solution was required.

As usual, I turned to PowerShell. I needed to use the name data in Active Directory to construct the email address. Then I had to insert the addresses into the ProxyAddress field so that they would be synchronized with the Office 365 mailboxes. Below is the code I came up with for accomplishing my goal.

Import-Module ActiveDirectory

$users = Get-ADUser -Filter * -SearchBase ("ou=users,dc=mydomain,dc=local")|select SammAccountName, Givenname, Surname

Foreach ($user in $users) 
{
     [string]$newproxyAddress = "SMTP:" + $user.Givenname + "." + 
     $user.Surname + "@" + "mydomain.com" 

     Set-ADUser -Identity $user.SamAccountName -Add 
     @{Proxyaddresses=$newproxyaddress}
}

This same code could easily be used to remove addresses by changing the -Add to -Remove. If you’re adding more than one address, the one labeled with a capital SMTP: will be the primary address. Set the others as a lowercase smtp:.

It worked like a charm. I ended up using this little snippet to build and insert three additional addresses for each of the users. In fact, it works so well, I will probably stop building Exchange servers in the local domain for managing email addresses and distribution lists.

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Tumblr (Opens in new window) Tumblr

Like this:

Like Loading…
  • October 2026
  • September 2026
  • August 2026
  • July 2026
  • May 2026
  • April 2026
  • March 2026
  • February 2026
  • January 2026
  • December 2025
  • November 2025
  • September 2025
  • August 2025
  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017

Top Posts & Pages

  • Ten Changes to Get the Most Out of Your Lenovo Legion Go
    Ten Changes to Get the Most Out of Your Lenovo Legion Go
  • Step by Step: Install / Upgrade EA Desktop and SIMS 4 on the Steam Deck With Proton Experimental (no Lutris)
    Step by Step: Install / Upgrade EA Desktop and SIMS 4 on the Steam Deck With Proton Experimental (no Lutris)
  • The Best Pillow Speaker I've Ever Used
    The Best Pillow Speaker I've Ever Used
  • Deploy a Linux VM on Hyper-V with Sound 20.04 Edition
    Deploy a Linux VM on Hyper-V with Sound 20.04 Edition
  • I SSD Swapped My Lenovo Legion Go. It Was Worth It.
    I SSD Swapped My Lenovo Legion Go. It Was Worth It.
  • Fixed Killer Network Manager Launcher Missing Link Error
    Fixed Killer Network Manager Launcher Missing Link Error
  • PowerShell: Backup and Repair/ Reset Windows Update.
    PowerShell: Backup and Repair/ Reset Windows Update.
  • How to Clear Microsoft Teams Ghost Notifications
    How to Clear Microsoft Teams Ghost Notifications
  • WSUS 2016 Client Connectivity Troubleshooting
    WSUS 2016 Client Connectivity Troubleshooting
  • PowerShell - Get-ADUser in a Multi-Domain Forest
    PowerShell - Get-ADUser in a Multi-Domain Forest
  1. Kevin Trent's avatar
    Kevin Trent on I Swapped My Wedding Band for a Samsung Galaxy Smart RingOctober 26, 2026

    I'm still wearing mine. However, you might want to check on the state of the Samsung ring's power issues. I…

  2. Kevin Trent's avatar
    Kevin Trent on Patching a Windows Enterprise Infrastructure with nothing but PowerShellOctober 26, 2026

    Yes, it would be faster. In the environment this script was developed for, there were issues with WinRM that prevented…

  3. skatterbrainz's avatar
    skatterbrainz on Patching a Windows Enterprise Infrastructure with nothing but PowerShellOctober 12, 2026

    Would it help speed up the overall processing time to switch from "Foreach ($Server in $Servers)" to "$Servers | ForEach-Object…

  4. Bruce Phelps's avatar
    Bruce Phelps on I Swapped My Wedding Band for a Samsung Galaxy Smart RingOctober 10, 2026

    Great information. I have been considering the same thing.

  5. Patching a Windows Enterprise Infrastructure with nothing but PowerShell – techbloggingfool.com on PowerShell: Backup and Repair/ Reset Windows Update.October 2, 2026

    […] The first tool I made for the project completely repaired and reset each server’s Windows Update mechanism. The script…

Powered by WordPress.com.
Loading Comments...
%d