1

I'm being tasked with creating a script that polls AD for specific information and then creates an appropriate email address based on that information. Please allow me to give you a bit of a rundown.

My company has 5 email domains that we have. All 5 are allowed through Exchange, but we only use one right now. Currently, everyone is setup with the default company.com email address. We have several different brands that we'd like to segment our users to in an effort to increase email deliverability to help keep our corporate email unaffected by IP reputation when marketing decides to release mass emails.

I manage a 7 server Exchange 2010 DAG (3 production, 3 DR, 1 3-day Lag). I'm fairly decent at PowerShell and pretty good at finding the code pieces I need, so I'm not looking for an entire script, but I'm having troubles with this certain pieces.

What the business wants to do is have a script that reads an attribute in AD, then based on that attribute, assigns it to the correct brand. So, for instance. If AD user has "Marketing" attribute, they would get marketing.com email address as their primary reply-to address while still retaining their company.com email address as a secondary. If an AD user has "building products" as their attribute, building.com would be their reply-to email address, etc.

I can get PowerShell to poll AD for an attribute. I can get it to create an email. I'm having troubles figure out how to get it to select one of the other domain names and not the default company.com email address.

Any insight would be greatly appreciated.

3
  • The default SMTP address is the one where SMTP is in all capitals. Commented Apr 7, 2015 at 14:34
  • 1
    Under which property are these attributes? Are they under office? Department? Job Title? Commented Apr 7, 2015 at 14:34
  • @pxed They will be defined by Department. Commented Apr 7, 2015 at 14:40

1 Answer 1

1

This is untested, but should get you in the right direction.

$peeps = get-aduser -filter * -properties department for-each ($person in $peeps){ ##Checks Department and sets new email if ($person.department -eq "building"){$email = $person.firstname+'.'+$person.surname +'@buildings.com'} elseif ($person.department -eq "otheroption"){$email = $person.firstname+'.'+$person.surname +'@whatever.com'} ##Changes existing email addresses to aliases and sets new email from above as primary $person.user = $user $smtp=get-aduser $user.samaccountname -properties proxyaddresses |select-object proxyaddresses $newsmtp = @() foreach($addr in $smtp.proxyaddresses){ if ($addr -notmatch $email -and $addr -cmatch "SMTP"){ $newsmtp = $newsmtp + $addr.replace("SMTP","smtp") } elseif ($addr -notmatch $email -and $addr -cnotmatch "SMTP"){$newsmtp = $newsmtp + $addr} } $emailproxy = 'SMTP:'+$email $newsmtp = $newsmtp + $emailproxy set-aduser $user.samaccountname -replace @{proxyaddresses=@($newsmtp)} } 
2
  • that looks exactly like something I can work with. Much appreciated! I'll report back when I get it working. Commented Apr 7, 2015 at 14:59
  • Great! Anytime! Feel free to comment back if you get stuck! Commented Apr 7, 2015 at 15:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.