The Exchange 2007 Wiki

Creating a Distribution Group for All Users on a Server via Shell

Here are two quick ways to create a distribution group that has all mailboxes on a specific server. This might be useful if you want to send an advance notice to all mailboxes on a server about an upcoming maintenance. 

Using a Dynamic Distribution Group

This is the easiest and most fool-proof way to do it. You simply create a dynamic distribution group that has a custom recipient filter.

New-DynamicDistributionGroup -Name "Server1 Users" -OrganizationalUnit Users -RecipientFilter "((RecipientType -eq 'MailboxUser' -and ServerName -eq 'Server1') -and -not(Name -like 'SystemMailbox{*'))"

The first part of the recipient filter string tells the dynamic distribution group to only get recipients of type "MailboxUser" that have their ServerName parameter equal to Server1. The second part of the recipient filter filters out the system mailboxes.

Using a regular Distribution Group

If you don't want to use dynamic distribution groups, you can accomplish the same result by filtering the results of the Get-Mailbox cmdlet and pipelining the output to the Add-DistributionGroupMember cmdlet. 

First, let's create a distribution group:

New-DistributionGroup -Type Distribution -SamAccountName "Server1 Users" -Name "Server1 Users" -OrganizationalUnit "Users"

Now we can use the Get-Mailbox cmdlet to return all mailboxes in the organization that reside on the server "Server1".  We can pipeline the output of the Get-Mailbox cmdlet to the Add-DistributionGroupMember cmdlet:

Get-Mailbox -Filter "ServerName -eq 'Server1'" | Add-DistributionGroupMember -Identity "Server1 Users"

The distribution group "Server1 Users" now has all the mailboxes that are hosted on server "Server1".

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 8/31/06 1:00 PM