Before we create a Contact object at the PowerShell command line, I would like to begin by creating a contact manually. There are two good reasons for this walk-through:
- To be clear which object we are discussing.
- To give us pointers for scripting, such as Alias cannot have spaces so we use an underscore in place.
Now we are ready to create an Exchange mail contact from the command line. The key PowerShell verb is ‘new’ as in New-Mailcontact; here are the properties we are going to script:
# Create Exchange mail contact via command-line
New-Mailcontact -Name Billy Cato`
Once we have created the Mail Contact here are more PowerShell commands to configure the Contact:
Get-Mailcontact (Only contacts that are enabled)
Get-Contact (All contacts including those disabled)
If you created a Mail Contact manually, then Get-mailcontact should display the name, both objects.
Get-mailcontact | Format-Table name, alias, ExternalEmailAddress -autosize.
Note 1: In PowerShell nouns are singular.
Note 2: ExternalEmailAddress
Once you have created an Exchange 2010 contact via command line, you need to enable it. For this you need values not only for -Identity, but also for ExternalEmailAddress. The value for the ExternalEmailAddress can be any of these:
- Contact alias
- Distinguished name (DN)
- E-mail address
- User principal name (UPN)
#Exchange 2010 PowerShell Script
Enable-MailContact -Identity BillyCato -ExternalEmailAddress "firstname.lastname@example.org"
Import users from a spreadsheet, complete with their mailbox. Just provide a list of the users with the fields in the top row, and save as .csv file. Then launch this FREE utility, match your Exchange fields with AD’s attributes, click and import the users. Optionally, you can provide the name of the OU where the new mailboxes will be born.
- Bulk-import new users and mailboxes into Active Directory.
- Seek and zap unwanted user accounts.
- Find inactive computers.
In order to disable a mailcontact you need its Alias or DN. For example
Disable-Mailcontact Billy Cato
Note disable is different from delete. If you wished to delete a mailcontact then the command is:
Remove-Mailcontact Billy Cato
More PowerShell Exchange 2010 Commands
The purpose of this simple illustration is to list all the roles of an Exchange Server. Observe the simplicity of PowerShell’s two-part instruction, the verb ‘Get’ coupled to the noun ‘ExchangeServer’.
# Example: PowerShell Exchange 2010 Command
Note 3: You could append -status to the above command.
Another Simple PowerShell Command
Get-Mailbox -Identity YourPerson
Note 4: You can also try the format domain\user instead of YourPerson.
Use PowerShell’s own Get-Command to extend your knowledge of Exchange 2010 contacts to list all cmdlets containing ‘Exchange’.
# Research Cmdlets containing Exchange
Note 5: Actually, *Exchange* doesn’t unearth many cmdlets, thus you could substitute *Mail* or *Address* in the above example.
Discover Parameters for Your Exchange 2010 Command
Once you find a particular cmdlet that interests you, the next step is to see if it has any useful parameters. Again use PowerShell’s own Get-Help cmdlet.
# Parameters for Exchange 2010 Commands
Get-Help Get-ExchangeServer -full
Note 6: I always append -full because I like to see Microsoft’s PowerShell examples. Incidentally, this is how I knew there was a parameter called -status.
SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
I have included some of the many PowerShell Exchange 2010 cmdlets, here are the three nouns to investigate Exchange address lists.
Combine with these PowerShell verbs: Get, Set, New and Remove, for example,
As usual, always try the ‘Get’ verb, but if you know what you are doing then experiment with: Mount, Dismount, Clean or even Remove.
Mailbox Policy Cmdlets
You can also use PowerShell cmdlets to modify the various email policies, the key nouns are: InboxRule and EmailAddressPolicy.
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.
Here are PowerShell commands for clustered configurations.
This PowerShell command displays the status of all your databases on all mailbox servers.
Get-MailboxDatabaseCopyStatus -server Exchsrv
Check to see that the database is mounted and healthy.
Get-MailboxDatabaseCopyStatus -identity DB1\Exchsrv
Note 7: The -identity parameter is frequently used in conjunction with Exchange cmdlets.
Here is a PowerShell Cmdlet which checks that mailboxes in a cluster are replicating correctly.
Digression: More PowerShell Commands for Exchange 2010 Containing ‘Test’
Do you remember how to research for more cmdlets with Get-Command? Well try:
Get-Command -verb Test
Summary of Create Contacts with PowerShell’s New-Mailcontact
It’s easy to use PowerShell’s New-Mailcontact to create an Exchange 2010 mail contact from the command line. I chose creating contacts as a vehicle for PowerShell because contacts are easier to manipulate than other Active Directory objects.
If you like this page then please share it with your friends