Tips from an other Admin

Managing email addresses with PowerShell

One of the most common tasks as an administrator is to find, change or add an email address to a user mailbox.  PowerShell makes this tasks a lot easier, you can easily find the users where the e-mail address belongs to and add or remove an alias.

In this article I will show you some tips howto find an e-mail address or ProxyAddress in Exchange or Active Directory and how to add or remove it.

Finding the owner of the e-mail address

I am working with Exchange Online here, so first we need to connect to Exchange Online.  You can use this connector script or run the following code:

There are multiple ways to find the owner of an email address, we start with the get-recipient cmdlet. This will return all mail-enabled objects (Mailboxes, mail users, contacts, distribution groups) , so this is the best place to start your search.

By using filters and wildcard we can search on a part of the email address:

In this case we are search for an email address that starts with “gr” (note the * wildcard at the end). I added “smtp:” before the start of the mail address, because if your aliases are managed through Active Directory, you will note that they start with “smtp:”.

Of course you can also add a wildcard in front of it, but this will widen the search query a lot.

The command above will return the user of object that has the searched name or letters in the email address, but it won’t show where. So select the EmailAddress field and expand it to show all values of the multi value object.

Searching Active Directory Objects

If you want to check or find the email address of an Active Directory object (user or group), we can use the get-ADObject or get-aduser cmdlet. First we need to import the ActiveDirectory module:

We can use the cmd below to search in Active Directory.  We will filter the results based on the mail address or proxyAddress. By using a wildcard and the -like switch we can search for a part of the email address.

Add or Remove a proxyAddress to an AD user

With PowerShell we can also easily add or remove a proxyaddress to an user:

Removing it: