General
The following code samples modify properties of a mailbox.
Alias
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Set alias
$mailboxParams.Alias = "%firstname,1%%lastname%"
# Save the changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
Simple Display Name
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Set Simple display name
$mailboxParams.SimpleDisplayName = "%lastname%, %firstname% (%initials%)"
# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
Hide from Exchange address lists
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Hide from address lists
$mailboxParams.HiddenFromExchangeAddressList = $true
# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
Exchange custom attributes
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Set custom attribute
$customAttributes = $mailboxParams.CustomAttributes
$customAttributes.IsModificationEnabled = $true
$customAttributes.SetCustomAttribute(1, "Date Modified: %datetime%")
# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
See also
- Performing Exchange tasks
- Writing ADSI scripts
- Server-side scripting
- IAdmExchangeMailParametersOps
- IAdmExchangeMailParameters
- IAdmExchangeMailboxParameters
- Online script repository