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
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
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")
# Bind to the contact
$contactDN = "CN=My Contact,CN=Contacts,DC=domain,DC=com"
$contact = $service.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
- Performing Exchange tasks
- Writing ADSI scripts
- Server-side scripting
- IAdmExchangeMailParametersOps
- IAdmExchangeMailParameters
- IAdmExchangeMailContactParameters
- Online script repository