Microsoft Exchange 2010 PowerShell Cookbook
上QQ阅读APP看书,第一时间看更新

Managing distribution groups

In many Exchange environments, distribution groups are relied upon heavily and require frequent changes. This recipe will cover the creation of distribution groups and how to add members to groups, which might be useful when performing these tasks interactively in the shell or through automated scripts.

How to do it...

  1. To create a distribution group use the New-DistributionGroup cmdlet:
    New-DistributionGroup -Name Sales
  2. Once the group has been created, adding multiple members can be done easily using a one-liner:
    Get-Mailbox -OrganizationalUnit Sales | 
      Add-DistributionGroupMember -Identity Sales
  3. We can also create distribution groups whose memberships are set dynamically:
    New-DynamicDistributionGroup -Name Accounting `
    -Alias Accounting `
    -IncludedRecipients MailboxUsers,MailContacts `
    -OrganizationalUnit Accounting `
    -ConditionalDepartment accounting,finance `
    -RecipientContainer contoso.com

How it works...

There are two types of distribution groups that can be created with Exchange. First, there are regular distribution groups, which contain a distinct list of users. Secondly, there are dynamic distribution groups, whose members are determined at the time a message is sent based on a number of conditions or filters that have been defined. Both types have a set of cmdlets that can be used to add, remove, update, enable, or disable these groups.

By default, when creating a standard distribution group, the group scope will be set to Universal. You can create a mail-enabled security group using the New-DistributionGroup cmdlet by setting the -Type parameter to Security. If you do not provide a value for the -Type parameter, the group will be created using the Distribution group type.

You can mail-enable an existing Active Directory universal distribution group using the Enable-DistributionGroup cmdlet.

After creating the Sales distribution group in our previous example, we added all of the mailboxes in the Sales OU to the group using theAdd-DistributionGroupMember cmdlet. You can do this in bulk or for one user at a time using the –Member parameter:

Add-DistributionGroupMember -Identity Sales -Member administrator 

Note

Distribution groups are a large topic and we're merely covering the basics here. See Chapter 5, Distribution Groups and Address Lists for in-depth coverage of distribution groups.

Dynamic distribution groups determine their membership based on a defined set of filters and conditions. When we created the Accounting distribution group, we used the -IncludedRecipients parameter to specify that only the MailboxUsers and MailContacts object types would be included in the group. This eliminates resource mailboxes, groups, or mail users from being included as members. The group will be created in the Accounting OU based on the value used with the -OrganizationalUnit parameter. Using the –ConditionalDepartment parameter, the group will only include users that have a department setting of either Accounting or Finance. And finally, since the -RecipientContainer parameter is set to the FQDN of the domain, any user located in the Active Directory could potentially be included in the group. You can create more complex filters for dynamic distribution groups using a recipient filter; see the recipe titled Working with Recipient Filters later in this chapter for an example.

Note

You can modify both group types using the Set-DistributionGroup and Set-DynamicDistributionGroup cmdlets.

There's more...

Just as when dealing with other recipient types, there are a couple of considerations that should be taken when it comes to removing distribution groups. You can remove the Exchange attributes from a group using the Disable-DistributionGroup cmdlet. The Remove-DistributionGroup cmdlet will remove the group object from the Active Directory and Exchange.

See also

  • Working with recipient filters
  • Reporting on distribution group membership in Chapter 5, Distribution Groups and Address Lists
  • Adding members to a distribution group from an external file in Chapter 5, Distribution Groups and Address Lists
  • Previewing dynamic distribution group membership in Chapter 5, Distribution Groups and Address Lists