Use PowerShell to Set-Contact in Exchange 2010
Set-Contact is a nifty PowerShell cmdlet for modifying an existing Exchange contact object. If you are changing multiple contacts then you could employ a second PowerShell cmdlet such as Get-Contact; the technique is to pipe its output into Set-Contact.
- Getting Started with Set-Contact
- Example 1: Change a Contact’s Phone Number
- List the Set-Contact Parameters
- Example 2: Piping Input with Get-User
♣
Getting Started with Set-Contact
Remember that the ‘Set’ verb makes changes, thus if you it’s your first time, I recommend you check with the corresponding Get-Contact first. Another technique is to wade straight in with Set-Contact, but append the -WhatIf parameter until you are sure that the modifications are what you expected.
Example 1: Change a Contact’s Phone Number
The only requirement with the Set-Contact cmdlet is that you supply the -Identity of the object.
Set-Contact -Identity "Guido" -MobilePhone 077 821 756
Note 1a: MobilePhone is only one of the many properties that you can amend, let us research more of Set-Contact’s parameters.
List the Set-Contact Parameters
Get-Help Set-Contact
Note 1b: Other interesting parameters of the ‘Phone’ family, include Pager and HomePhone.
Example 2: Piping Input with Get-User
One of the best features of PowerShell is piping. In this instance obtain a flow of ‘Leads’ using another cmdlet, and stream them into Set-Contact so that you can adjust their ‘Department" value.
Get-User -OrganizationalUnit "Contacts" | Set-Contact -Department "Sales"
Note 2a: An alternative source cmdlet is Get-Mailbox, the piping techique would be the same as in the above script.
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.
Compare PowerShell with the EMC
I like to take a walk-through of the EMC (Exchange Management Console), the benefit is that I can compare the PowerShell script with what’s in the Exchange GUI.
- Launch the EMC, navigate to the Recipient Configuration, Mail Contact (see screenshot right)
PowerShell New-Mailcontact
It’s also possible to create new contacts.
# Create a Contact with PowerShell
New-Mailcontact -Name Guido Smith `
-ExternalEmailAddress: [email protected] `
-OrganizationalUnit Worcester
-Alias GuidoSm
See more on creating contacts.
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.
In order to disable a mailcontact you need its Alias or DN. For example
Disable-Mailcontact Martha Jones
Note disable is different from delete. If you wished to delete a mailcontact then the command is:
Remove-Mailcontact Martha Jones
See more on PowerShell Contacts for Exchange 2010.
Guy 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
Summary of Create Contacts with PowerShell
Set-Contact is a nifty PowerShell cmdlet for changing a property on existing Exchange contact object, for example, MobilePhone, City or Company.
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