Add email address to mail contact powershell

To add an email address to a MailContact object in PowerShell, you can use the following syntax:

$contact = [Microsoft.Exchange.Data.Storage.MailContact]::new()
$contact.EmailAddress = "[email protected]"

This will create a new MailContact object and set the EmailAddress property to the specified email address.

If you want to add an existing contact to a MailContact object, you can use the following syntax:

$contact = [Microsoft.Exchange.Data.Storage.MailContact]::new()
$contact.EmailAddress = "[email protected]"
$contact.DisplayName = "User Name"
$contact.Save()

This will create a new MailContact object, set the EmailAddress and DisplayName properties, and then save the contact to the Exchange mailbox.

You can also use the New-MailContact cmdlet to create a new MailContact object and add an email address:

New-MailContact -Name "User Name" -EmailAddresses "[email protected]"

This will create a new MailContact object and add the specified email address to it.

Note: You need to have the Exchange PowerShell module installed and imported to use these commands. You can import the module by running the following command:

Import-Module -Name Exchange

Also, you need to have the necessary permissions to create and manage MailContact objects in your Exchange mailbox.