Skip to content

Mailbox policies

The following code samples assign mailbox policies.

Sharing Policy

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

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

# Sharing Policy DN
$sharingPolicyDN = 
    "CN=SharingPolicy01,CN=Federation," +
    "CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=example,DC=com"

$sharingPolicy = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$sharingPolicy.ObjectDN = $sharingPolicyDN
$mailboxParams.SharingPolicy = $sharingPolicy

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Role Assignment Policy

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

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

# Role Assignment Policy DN
$roleAssignmentPolicyDN = 
    "CN=End User Policy,CN=Policies,CN=RBAC," +
    "CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=example,DC=com"

$roleAssignmentPolicy = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$roleAssignmentPolicy.ObjectDN = $roleAssignmentPolicyDN
$mailboxParams.RoleAssignmentPolicy = $roleAssignmentPolicy

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Retention Policy

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

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

# Retention Policy DN
$retentionPolicyDN = 
    "CN=Business General,CN=Retention Policies Container," +
    "CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=example,DC=com"

$retentionPolicy = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$retentionPolicy.ObjectDN = $retentionPolicyDN
$mailboxParams.RetentionPolicy = $retentionPolicy

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Address Book Policy

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

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

# Address Book Policy DN
$addressBookPolicyDN = 
    "CN=AddressBookPolicy,CN=AddressBook Mailbox Policies," +
    "CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=example,DC=com"

$addressBookPolicy = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$addressBookPolicy.ObjectDN = $addressBookPolicyDN
$mailboxParams.AddressBookPolicy = $addressBookPolicy

# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

See also