Script Repository


Create dynamic distribution list

March 01, 2017
1715

The script creates a dynamic distribution list consisting of users with Exchange mailboxes located in a certain Organizational Unit and belonging to a certain department. To use the script with Adaxes, you need to:

  1. Define 3 attributes that will be used to specify the name and email alias of the distribution list and also the department of the users you want to include. It is recommended to use Adaxes custom attributes for this purpose. They are not stored in Active Directory, but can be used the same as any other attribute of AD objects.

    For example, you can use CustomAttributeText1 to specify a name for a distribution list, CustomAttributeText2 to specify an alias, and CustomAttributeText3 to specify the department of the users to include.

  2. Create a Home Page Action that allows modifying the above 3 attributes of the currently logged on user. The values for the attributes will be used by the script to grab the user input. For information on how to create such an action, see section Modify Object in Configure Home Page Actions.
    • On Step 1 of the section, select Modify User.
    • On Step 2, select the Always perform for the current user option.
    • On Step 3, customize the form to include only the 3 attributes you've chosen in step 1.
  3. Create a Business Rule triggered after modifying a user that runs the script.
  4. Change the name under which the properties appear in Adaxes to reflect their function.

Parameters:

  • $exchangeServer - specifies the fully qualified domain name (FQDN) of your Exchange Server;
  • $mailboxOu - specifies the Distinguished Name (DN) of the Organizational Unit where the distribution list members are located;
  • $targetOu - specifies the Distinguished Name (DN) of the Organizational Unit where distribution lists will be created;
  • $nameProperty - specifies the LDAP Display Name of the attribute that is used to specify the name of new distribution lists;
  • $mailAliasProperty - specifies the LDAP Display Name of the attribute that is used to specify the email alias;
  • $departmentProperty - specifies the LDAP Display Name of the attribute that is used to specify the department of the users to include.
    You can use value references for $mailboxOu and $targetOu. For example, if you specify %adm-ParentDn% for $targetOu, distribution lists will be created in the OU where the logged in user is located.
Edit Remove
PowerShell
$exchangeServer = "exchangeserver.example.com" # TODO: modify me
$mailboxOu = "OU=New York Office,OU=Offices,DC=example,DC=com" # TODO: modify me
$targetOu = "OU=Distribution Lists,DC=example,DC=com" # TODO: modify me
$nameProperty = "adm-CustomAttributeText1" # TODO: modify me
$mailAliasProperty = "adm-CustomAttributeText2" # TODO: modify me
$departmentProperty = "adm-CustomAttributeText3" # TODO: modify me

if (-not($Context.IsPropertyModified($nameProperty) -or $Context.IsPropertyModified($mailAliasProperty) -or $Context.IsPropertyModified($departmentProperty)))
{
    return
}

$name = $Context.GetModifiedPropertyValue($nameProperty)
$mailAlias = $Context.GetModifiedPropertyValue($mailAliasProperty)
$department = $Context.GetModifiedPropertyValue($departmentProperty)

if (-not(([System.String]::IsNullOrEmpty($name)) -or ([System.String]::IsNullOrEmpty($mailAlias)) -or ([System.String]::IsNullOrEmpty($department))))
{
    try
    {
        # Connect to Exchange Server
        $session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri https://$exchangeServer/powershell
        Import-PSSession $session -DisableNameChecking -AllowClobber

        # Create dynamic distribution list
        New-DynamicDistributionGroup -Name $name -Alias $mailAlias -ConditionalDepartment $department -IncludedRecipients "MailboxUsers" `
                                     -RecipientContainer $mailboxOu -OrganizationalUnit $targetOu
    }
    finally
    {
        # Release resources
        if ($session) { Remove-PSSession $session }
    }
}
else
{
    $Context.LogMessage("One or more of the required properties were not specified to create a dynamic distribution list: Name, Email Alias, Department", "Warning") # TODO: modify me
}

# Clear custom attributes
$Context.TargetObject.Put($nameProperty, $NULL)
$Context.TargetObject.Put($mailAliasProperty, $NULL)
$Context.TargetObject.Put($departmentProperty, $NULL)

$Context.TargetObject.SetInfoEx(@($nameProperty,$mailAliasProperty,$departmentProperty))

Comments ( 0 )
No results found.
Leave a comment