Skip to content

General

This code sample retrieves the following parameters of a mail-enabled contact:

  • Alias
  • Use MAPI rich text format
  • Hide from Exchange address lists
  • Exchange custom attributes

Note

In the below code sample, the $contactParams variable represents Exchange properties of a mail-enabled contact. To retrieve the properties, use the IAdmExchangeMailParametersOps::GetMailParameters method.

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

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

# Bind to the contact
$contactDN = "CN=My Contact,CN=Users,DC=domain,DC=com"
$contact = $admService.OpenObject("Adaxes://$contactDN", $NULL, $NULL, 0)

# Get Exchange properties
$contactParams = $contact.GetMailParameters()
# The $contactParams variable represents Exchange properties of a mail-enabled contact

# Alias
Write-Host "Alias:" $contactParams.Alias

# Use MAPI rich text format
$useMapiRichTextFormat = $contactParams.UseMapiRichTextFormat
Write-Host "Use MAPI rich text format: " -NoNewline
switch ($useMapiRichTextFormat)
{
    "ADM_EXCHANGE_USEMAPIRICHTEXTFORMATTYPE_NEVER"
    {
        Write-Host "Never"
    }
    "ADM_EXCHANGE_USEMAPIRICHTEXTFORMATTYPE_ALWAYS"
    {
        Write-Host "Always"
    }
    "ADM_EXCHANGE_USEMAPIRICHTEXTFORMATTYPE_USEDEFAULTSETTINGS"
    {
        Write-Host "Use default settings"
    }
}

# Hide from Exchange address lists
Write-Host "Hide from Exchange address lists:" $contactParams.HiddenFromExchangeAddressList

# Custom attributes
$customAttributes = $contactParams.CustomAttributes
Write-Host "Custom attributes"
for($i = 1; $i -le 15; $i++)
{
    $attributeName = $customAttributes.BuildAttributeName($i)
    $attributeValue = $customAttributes.GetCustomAttribute($i)
    Write-Host "`t$attributeName`: $attributeValue"
}

See also