E-mail addresses

The following code sample modifies e-mail addresses of a mail-enabled group.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the group
$groupDN = "CN=MyGroup,CN=Users,DC=example,DC=com"
$group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0)

# Create an instance of the 'AdmExchangeMailGroupParameters' class
$groupParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailGroupParameters"

# Do not update e-mail addresses based on e-mail address policy automatically
$groupParams.EmailAddressPolicyEnabled = $false

$emailAddresses = $groupParams.EmailAddresses

# Create a new SMTP address
$emailAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = "%name%.HelpDesk@example.com"
$emailAddress.IsPrimary = $true

# Add new e-mail address to the existing list
$emailAddresses.Add("ADS_PROPERTY_APPEND", $emailAddress)
$emailAddresses.OverrideOldValues = $false
$groupParams.EmailAddresses = $emailAddresses

# Save changes
$group.SetMailParameters($groupParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

See also