I’m new to PowerShell and I’m trying to add three proxyAddresses to each of my AD users. There are 3 domains that are used for email and each user uses one of those 3 domains as their SMTP: address and the other two need to be smtp: addresses. I was able to populate all of my AD users with our legacy email domains (with another script that someone helped me with), but I’m having trouble with having a script recognize the user’s existing SMTP: address as “firstname.lastname@domain1.com” and adding the other two as smtp:firstname.lastname@domain2.com. If everyone used the same SMTP: domain I could do it, but having to look at the user’s current SMTP:, not touching it, and adding the other two domains as smtp: is really confusing me.
Could someone help me with a script for this, please?
How about you take proxyAddresses with -clike ‘SMTP:*’ to string and then split it so you got the firstname.lastname. Then you could use that as base and add those domains to end of it and add prefix smtp: and set it with set-aduser -add @{proxyaddresses=$secondDomain,$thirdDomain}?
No problem. If I was creating this I would use If or Switch to determ added domains dependind on what domain is primary, then crosscheck that if this mail address is already there.
Edit. Here’s non tested example to point you to direction, not the prettiest but… To be faster Switch would be better.
A minor change and also very untested. Check to make sure those secondary addresses aren’t already in there. Even with this change, you run the risk of adding a duplicate where someone else has a similar name and the names were not duplicated consistently.
Instead of combining all of my tasks into one script I have broken what I need down into 3 lines of code to help mitigate any duplicate smtp entries.
I am 99% there, I’m just having trouble getting the script to add givenname.sn@domain.com to my AD account. I have changed the code around and all I get is “smtp:.domain1.com” and “smtp:.domain2.com” added to my proxyAddresses.
$Domains = "domain1.com","domain2.com"
$proxies = foreach ($domain in $domains) {"smtp:$($_.givenname).$($_.sn)@$domain"}
Get-ADuser user1 -properties mail | Set-ADuser -Add @{Proxyaddress = $Proxies}
How should that line be written to pull the givenname and sn from an AD account and add a proxyaddress to the account as givenname.sn@domain1.com and …domain2.com?
I was actually able to get this working last night. I needed to lose the parenthesis around the givenname and surname and pipe it to foreach, enclosing everything in squiggly brackets.
I managed an Office 365 migration and learned a lot about emailaddress and proxyAddress, this weekend.
This thread was very useful and helped me fight through problems from the default configuration, where the domain and forest functional levels are still 2003 (for now…)
Long story short - I am providing my code and saying thanks to you @skalizar and a post where Dave Wyatt had commented