r/PowerShell • u/Will_ADM • Sep 30 '26
Question Powershell script to bulk update AD users email alias with diff format.
Ok so I work for a company who's legacy emails are first initial + surname@domain.net e.g Bob Morton = bmorton@domain.net
new users have their accounts as firstname.lastname@domain2.co.uk (Bob.morton@domain2.co.uk)
I've been asked to add the 'new' email style address and domain as an alias to all users. There's a few hundred so obvs would rather find a ps script to do this. I'd appreciate all and any help.
13
Upvotes
20
u/fdeyso Oct 03 '26
Tbh i know it’s extra work, BUT, i’d export the existing users to a csv, generate their new email address in there and check if it’s all ok (no duplicates with other users), then use this csv in ps to set the emails.
6
u/bTOhno Oct 04 '26
If you're on-prem with Exchange Online (hybrid) I'll point you to looking into the ad user attribute known as proxyAddress Primary email gets SMTP:user@domain Alias gets email smtp:alias@aliasdomain
3
u/PinchesTheCrab Oct 03 '26
This is pretty straightforward to script, but the wrinkle is always whether names are truly unique and whether anyone has conflicting aliases already.
2
u/theDukeSilversJazz Oct 03 '26
What have you done that hasn’t worked? The best way to learn is a test user or two to flesh out the script.
1
u/purplemonkeymad Oct 03 '26
If you still have an on-prem exchange server, this is a 3 minute edit to the email address policy on the ui.
For the script you'd still have to know what kind of setup you have, On-prem exchange, hybrid, removed exchange server, fully cloud managed mailbox?
1
u/No_Crab_4093 Oct 04 '26
Claude this and test with some test users and call it a day. No need to complicate it. But as one suggested do a check and make sure there are no duplicate emails from the existing employees by going to that format
0
u/wishmaster1965 Oct 03 '26
I was a contracter at a whiskey company and I saw they had a 3rd party in to determine if they could move their email to office 365,they ran a a tool to check and it failed. I asked the guy what it failed and it was the upn, so I told the IT manager I could fix this, wrote a small script and they reran the tool and it passed. I was then tasked with moving users on exchange worldwide to office 365. Just in the middle of writing the scripts they had something happen and I was asked to move all rooms to 365. Once all users were over I wrote a few scripts for the service desk to manage things in 365.
That gig got me a job in this company for 7 years with lots of free booze. 🥳
Don't have these scripts any more as I retired.
I was initially just interested in scripting when I saw this 3rd party so doing scripting launched a 2nd career.
Never stop learning, good things can happen.