Mail-enabling users

The following code sample mail-enables a user.

[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 user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Mail-enable the user
$alias = "%username%" # Alias
$externalMailAddress = "Jsmith@domain.com" # External e-mail address
$externalMailAddressType = "SMTP" # External e-mail address type

$user.MailEnable($alias, $externalMailAddress, $externalMailAddressType, $null)

See also