PowerShell Script – Exchange Mailcontact

PowerShell Script – Exchange 2007 Mailcontact Create new MailContact with Exchange 2007 System Manger

This page explains how to create Contact and  – Mailcontact objects in Exchange 2007.  If you are looking for a straightforward example to learn Exchange 2007 PowerShell commands, then Mailcontact is an ideal vehicle to practise.  The key verbs are: get, new and disable.

Topics for Mailcontact

 ♣

Walk-through with Exchange Management Console

To begin with, I recommend a walk-through with the Exchange Management Console.  Firstly it will clarify the objects that we are creating, secondly it will alert you to nuances such as Aliases don’t have spaces.

Get-Mailcontact

As a prelude, open the PowerShell command prompt and type:

Get-mailcontact (Only Mail enabled objects)
Get-contact (Includes disabled contacts)

Type these commands after you have created a new mail object with the GUI, and again after you employ PowerShell to create the Mail Contact.

Note 1: As with so many PowerShell nouns contact is both case insensitive and singular.

New-Mailcontact

Our mission is to achieve with PowerShell what you could do manually with the Wizard (See Right).  Once you issue the plain command New-Mailcontact, you need to provide information about:

ExternalEmailAddress:
Name:
Alias:
OrganizationalUnit:

Create New Mail Contact Wizard

Example 1 Create a New Mailcontact called Eddie Jones

New-Mailcontact
ExternalEmailAddress: [email protected]
Name: Ernie Prost
Alias: ErnieProst
OrganizationalUnit: Droitwich

Once created you should see your new Mailcontact.  Try viewing all such objects try:

Get-mailcontact | ft -autosize name, alias, ExternalEmailAddress.

Note 2: ft is an alias or shorthand for Format-Table.

Guy Recommends:  SolarWinds’ Free Bulk Import ToolFree Download Solarwinds Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.

Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.

If you need more comprehensive application analysis software,
Download a free trial of SAM (Server & Application Monitor)

Disable-Mailcontact

Disabling is different from deleting the object.  Disabled Mail Contacts appear in the Exchange System Manager and can be verified by comparing Get-Mailcontact with Get-Contacts.  You can also confirm by checking the contents of the Disconnected folder in the Exchange Management Console.

Example 2 Disable a Mailcontact

Disable_Mailcontact ‘Eddie Jones’

Note 3: For names with spaces, enclose them with single quotes.

Test your command with Get-Contact.  Compare the results with Get-Mailcontact.  See Exchange Nouns also see Exchange PowerShell Verbs

Exchange Monitor from SolarWindsGuy Recommends: The SolarWinds Exchange Monitor

Here is a free tool to monitor your Exchange Server.  Download and install the utility, then inspect your mail queues, monitor the Exchange server’s memory, confirm there is enough disk space and check the CPU utilization.

This is the real deal – there is no catch.  SolarWinds provides this fully-functioning freebie, as part of their commitment to supporting the network management community.

Free Download of SolarWinds Exchange Monitor

PowerShell Scripts for the Outlook Client

It's possible to use PowerShell to read and even manipulate the Outlook Client.

Here is an example which lists the senders' email addresses in the Inbox folder.

$Folder = "InBox"
$Outlook = New-Object -ComObject Outlook.Application
$Namespace = $Outlook.GetNameSpace("MAPI")
$NameSpace.Folders.Item(1)
$Email = $NameSpace.Folders.Item(1).Folders.Item($Folder).Items
$Email | Sort-Object SenderEmailAddress -Unique | FT SenderEmailAddress

See more PowerShell's and Outlook »

Summary of Controlling Mailcontact

Mailcontact is an Exchange object and a PowerShell noun.  In order to control Mailcontact, master the verbs get, new and disable.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell ‘where‘  • PowerShell ‘Sort’

Windows PowerShell Modules  • Import-Module  • PowerShell Module Directory 

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links.