Working with contacts

Once you've started managing mailboxes using the Exchange Management Shell, you'll probably notice that the concepts and command syntax used to manage contacts are very similar. The difference, of course, is that we need to use a different set of cmdlets. In addition, we also have two types of contacts to deal with in Exchange. We'll take a look at how you can manage both of them in this recipe.

How to do it...

Let's see how to work with contacts using the following steps:

  1. To create a mail-enabled contact, use the New-MailContact cmdlet:
    New-MailContact -Alias rjones `
    -Name "Rob Jones" `
    -ExternalEmailAddress rob@fabrikam.com `
    -OrganizationalUnit sales
    
  2. Mail-enabled users can be created with the New-MailUser cmdlet:
    New-MailUser -Name 'John Davis' `
    -Alias jdavis `
    -UserPrincipalName jdavis@contoso.com `
    -FirstName John `
    -LastName Davis `
    -Password (ConvertTo-SecureString -AsPlainText P@ssw0rd `-Force) `
    -ResetPasswordOnNextLogon $false `
    -ExternalEmailAddress jdavis@fabrikam.com
    

How it works...

Mail contacts are useful when you have external e-mail recipients that need to show up in your global address list. When you use the New-MailContact cmdlet, an Active Directory contact object is created and mail-enabled with the external e-mail address assigned. You can mail-enable an existing Active Directory contact using the Enable-MailContact cmdlet.

Mail users are similar to mail contacts in the way that they have an associated external e-mail address. The difference is that these objects are mail-enabled Active Directory users and this explains why we need to assign a password when creating the object. You might use a mail user for a contractor who works onsite in your organization and needs to be able to log on to your domain. When users in your organization need to e-mail this person, they can select them from the global address list and messages sent to these recipients will be delivered to the external address configured for the account.

When dealing with mailboxes, there are a couple of things that should be taken into consideration when it comes to removing contacts and mail users. You can remove the Exchange attributes from a contact using the Disable-MailContact cmdlet. The Remove-MailContact cmdlet will remove the contact object from the Active Directory and Exchange. Similarly, the Disable-MailUser and Remove-MailUser cmdlets work in the same fashion.

There's more...

Like mailboxes, mail contacts and mail-enabled user accounts have several Active Directory attributes that can be set, such as the job title, company, department, and so on. To update these attributes, you can use the Set-* cmdlets that are available for each respective type. For example, to update our mail contact, we can use the Set-Contact cmdlet with the following syntax:

Set-Contact -Identity rjones `
-Title 'Sales Contractor' `
-Company Fabrikam `
-Department Sales

To modify the same settings for a mail-enabled user, use the Set-User cmdlet:

Set-User -Identity jdavis `
-Title 'Sales Contractor' `
-Company Fabrikam `
-Department Sales

Both cmdlets can be used to modify a number of different settings. Use the help system to view all of the available parameters.

See also

  • Using the help system in Chapter 1, PowerShell Key Concepts
  • Adding, modifying, and removing mailboxes