content.php

Powershell Script – Automate Email Address in AD

Exchange refugees often wonder how they can replace the automatic process of populating AD mail fields after they migrate away from exchange. The solution is usually a lot simpler than people expect. You literally just write a value to them.

Here’s a script that lets you pass in a username. It prepends it to your domain name, and it writes it to the Mail field in Active Directory.

Param(
    [string]$username
}

Import-Module ActiveDirectory

$emailAddress = $username + '@mydomain.com'
Set-ADUser -Identity $username -EmailAddress $emailAddress

However you are automating your account creating process, just add this as a step and pass it the username.

If you’re not already automating your account creation process, you would just need to run a script to find new user accounts, and for each new user account, call this script. (See my post on finding new user accounts and my post on scheduling automation tasks).

Leave a Reply

Your email address will not be published. Required fields are marked *