Use PowerShell to Create Exchange 2010 Contacts
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.
PowerShell New-Mailcontact
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:
OrganizationalUnit:
ExternalEmailAddress:
Name:
Alias:
# Create Exchange mail contact via command-line
New-Mailcontact -Name Billy Cato`
-ExternalEmailAddress: [email protected]`
-OrganizationalUnit Boston`
-Alias BillyCato
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)
Get-Mailcontact
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
Enable-Mailcontact
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:
- ADObjectID
- GUID
- Contact alias
- Distinguished name (DN)
- Domain\SamAccountName
- LegacyExchangeDN
- E-mail address
- User principal name (UPN)
#Exchange 2010 PowerShell Script
Enable-MailContact -Identity BillyCato -ExternalEmailAddress "[email protected]"
Guy Recommends: SolarWinds’ Free Bulk Mailbox Import Tool
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.
There are also two bonus tools in the free download, and all 3 have been approved by Microsoft:
- Bulk-import new users and mailboxes into Active Directory.
- Seek and zap unwanted user accounts.
- Find inactive computers.
Download your FREE bulk mailbox import tool.
Disable-Mailcontact
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
See more on PowerShell Contacts for Exchange 2010.
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
Get-ExchangeServer
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.
Research PowerShell’s Exchange Cmdlets
Use PowerShell’s own Get-Command to extend your knowledge of Exchange 2010 contacts to list all cmdlets containing ‘Exchange’.
# Research Cmdlets containing Exchange
Get-Command *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.
See more simple PowerShell examples for Exchange Server.
Guy Recommends: A Free Trial of the Network Performance Monitor (NPM) v11.5
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.
Download a free trial of SolarWinds’ Network Performance Monitor
PowerShell Exchange AddressList Cmdlets
I have included some of the many PowerShell Exchange 2010 cmdlets, here are the three nouns to investigate Exchange address lists.
- AddressList
- GlobalAddressList
- AddressListPaging
Combine with these PowerShell verbs: Get, Set, New and Remove, for example,
- New-AddressList
- Get-AddressListPaging
- Set-GlobalAddressList
PowerShell Exchange Mailbox Cmdlets
- StoreUsageStatistics
- MailboxDatabase
- StoreMailbox
- Database
- MailboxServer
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.
Guy Recommends: Free WMI Monitor for PowerShell
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.
Download your free copy of WMI Monitor
Monitoring Exchange 2010 High Availability
Here are PowerShell commands for clustered configurations.
Get-MailboxDatabaseCopyStatus
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.
Test-ReplicationHealth
Here is a PowerShell Cmdlet which checks that mailboxes in a cluster are replicating correctly.
Test-ReplicationHealth Exchsrv
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
# Test-MailFlow
# Test-OutlookWebServices
# Test-ServiceHealth
# Test-SystemHealth
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
See more PowerShell Cmdlets for Exchange 2010:
• Exchange 2010 Home • Get-ExchangeServer • Set-ExchangeServer • New-SystemMessage • SP1
• Get-Mailbox • Get-MailboxStatistics • Connect-Mailbox • Enable-Mailbox • Disable-Mailbox
• PowerShell Exchange Cmdlets • Set-Contact • New-Mailcontact • Add-MailboxPermission -identity