Recipient Management Using One-line Commands in Exchange Management Shell (PART 1)

 

Recipient management in Microsoft Exchange Server 2007 can be completed by using either the graphical user interface (GUI) in Exchange Management Console or by using command lines in the Exchange Management Shell.

The actions that you take in the Exchange Management Console can also be completed by typing a one-line command in the Exchange Management Shell. This topic describes some common recipient management scenarios that are completed by using Exchange Management Console. This topic also describes how the same actions can be completed by using a one-line command in Exchange Management Shell.

The scenarios that are described here are organized into the following categories:

  • Mailbox creation

  • Change management

  • Bulk management

  • Reporting

Mailbox Creation

The following Mailbox types are included in Microsoft Exchange:

  • MailboxUser

  • ConferenceRoomMailbox

  • EquipmentMailbox

  • SharedMailbox

  • LinkedMailbox

  • LegacyMailbox

The SharedMailbox type can be managed only in the Exchange Management Shell. The LegacyMailbox type is used for interoperability together with Microsoft Exchange 2000 Server or together with Microsoft Exchange Server 2003. This type has limited management in Microsoft Exchange. The other four mailbox types can be managed by using the Exchange Management Console or the Exchange Management Shell.

If you are an administrator, you can perform the following actions:

  • Create a new mailbox, and mailbox-enable the user at the same time by using one step

  • Mailbox-enable an existing user

For example, to create a new mailbox by using the New Mailbox wizard in the Exchange Management Console, right-click Recipient Configuration, and then click New Mailbox. Or, click New Mailbox in the action pane. In the New Mailbox wizard, you can choose to create a new user and to mailbox-enable it in one step, or you can choose to mailbox-enable an existing user. During this process, you can specify any necessary mailbox information, such as mailbox type.

The same process can be completed by entering one-line commands in the Exchange Management Shell. The following table describes the actions and the one-line commands that complete the action.

Note

You can enter less than the full parameter name if the name is unique. For example, the org parameter is used to specify "OrganizationalUnit" in the following example.

Note

You are prompted for any parameters that you do not include in the command line but that are required for the cmdlet to complete.

Action One-line command

Create a new mailbox-enabled user

new-Mailbox -alias <User_Alias> -name <Mailbox_Name> -database "Mailbox Database" -org Users -UserPrincipalName <User_Alias @example.com> Password: <userpassword>

Create a new resource mailbox (Conference Room or Equipment)

New-Mailbox -alias <User_Alias> -name <Mailbox_Name> -database "Mailbox Database" -org Users <-Room | -Equipment> -UserPrincipalName <User_Alias @example.com>

Create a shared mailbox

new-Mailbox -alias <User_Alias> -name <Mailbox_Name> -database "Mailbox Database" -org Users -shared -UserPrincipalName <User_Alias@example.com>

Create a new linked mailbox

New-Mailbox -alias <User_Alias> -name <Mailbox_Name> -database "Mailbox Database" -org Users -LinkedMasterAccount <Account@userdomain.com> -LinkedDomainController <userdomain-dc-01> -UserPrincipalName <User_Alias@example.com>

Mailbox-enable an existing user as a user mailbox

Enable-Mailbox logondisableduser -database "Mailbox Database"

Mailbox-enable an existing (AD logon-disabled) user as a resource mailbox (Conference Room or Equipment)

Enable-Mailbox logondisableduser <-Room | -Equipment> -database "Mailbox Database"

Mailbox-enable an existing (AD logon-disabled) user as a linked mailbox

Enable-Mailbox logondisableduser -database "Mailbox Database" -LinkedMasterAccount <Account@userdomain.com> -LinkedDomainController <Userdomain-dc-01>

Note

For both the new-mailbox and enable-mailbox examples, you usually have to use the -LinkedCredential parameter to specify the required credential to complete the lookup in the user domain.

Change Management

Use the Exchange Management Console or the Exchange Management Shell to move a mailbox, to disable a mailbox, to remove a mailbox, or to change mailbox settings for an existing mailbox.

Note

These procedures require that you have Administrator permissions.

Move, Disable, or Remove Mailboxes

To move, disable, or remove a mailbox by using the Exchange Management Console, right-click the mailbox name, and then click the appropriate command for the action that you want to complete. For example, to remove a mailbox, locate the mailbox in the Recipient Management node, right-click the mailbox, and then click Remove.

The same process can be completed by entering one-line commands in the Exchange Management Shell. The following table describes the actions and the one-line commands that complete the actions.

Action One-line command

Move an individual mailbox

Move-Mailbox <Mailbox_Name> -targetdatabase "Mailbox Database"

Move all mailboxes that are stored on a server to a target mailbox database

Get-Mailbox -server <Server_Name> | Move-Mailbox -targetdatabase "Mailbox Database"

Disable a single mailbox

Disable-Mailbox <Mailbox_Name>

Disable all mailboxes that are stored on a server

Get-Mailbox -server <Server_Name> | Disable-Mailbox

Remove a single mailbox-enabled user

Remove-Mailbox <Mailbox_Name>

Remove all mailbox-enabled users that are stored on a server

Get-Mailbox -server <Server_Name> | Remove-Mailbox

Extensive filtering is possible in the Exchange Management Shell. The Move-Mailbox cmdlet can directly take a pipelined input of mailbox objects that are to be moved. Therefore, any filtered output from Get-Mailbox can be used to feed a Move-Mailbox action. The following table describes the action and the one-line command that completes the action.

Action One-line command

Move all mailboxes that have CustomAttribute1 set to "Executive"

Get-Mailbox -Filter { CustomAttribute1 -eq 'Executive' } | Move-Mailbox -TargetDatabase MyTargetMDB

Set Storage Quotas on a Mailbox

You can set storage quotas on a mailbox by using the Exchange Management Console. To do this, open Properties for the mailbox that you want to configure, and then double-click Storage Quotas on the Mailbox Settings tab. You can then configure the Storage Quotas properties.

To complete the same action by using the Exchange Management Shell, use the following one-line command.

Action One-line command

Set storage quotas on a mailbox

Set-Mailbox <Mailbox_Name> -UseDatabaseQuotaDefaults:$False -IssueWarningQuota <Quota_In MB> -ProhibitSendQuota <Quota_In MB> -ProhibitSendReceiveQuota <Quota_In MB>

Set Delivery Options on a Mailbox

You can set delivery options on a mailbox by using the Exchange Management Console. To do this, open Properties for the mailbox that you want to configure, and then double-click Delivery Options on the Mail Flow Settings tab. You can then configure the Delivery Options properties. For example, you may want to configure a mailbox to forward mail to another recipient and to set the recipient's limits.

To complete the same action by using the Exchange Management Shell, you can use the following one-line command.

Action One-line command

Set delivery options on a mailbox

Set-Mailbox <Mailbox_Name> -DeliverToMailboxAndForward:$True -ForwardingAddress <User_Alias@example.com> -RecipientLimits <Recipient_Limit>

Add a New E-mail Address to a Mailbox

You can add a new e-mail address to a mailbox by using the Exchange Management Console. To do this, open Properties for the mailbox that you want to configure, and then click Add on the E-mail Addresses tab. You can then type the new address.

Note

If the Automatically update e-mail addresses based on e-mail address policy check box is selected on the E-Mail Addresses tab, the primary SMTP e-mail address cannot be modified, and you cannot replace all configured e-mail addresses on the object. However, you can add additional SMTP secondary e-mail addresses.

To complete the same action by using the Exchange Management Shell, you can use the following one-line command.

Action One-line command

Add a new e-mail address to a mailbox

$mbx = get-Mailbox <Mailbox_Name>;

$mbx.EmailAddresses += "<newaddr@example.com>";

$mbx | set-Mailbox

Configure Mailbox Permissions

The "Send on behalf" permission can be granted by using the Exchange Management Console. To do this, open the properties for the mailbox, and then configure the "Send on behalf" permission on the Mail Flow Setting tab.

The "Send-As" permission setting and the "Grant full mailbox access" setting can be set only by using the Exchange Management Shell. The following table describes the actions and the one-line commands that complete the actions.

Action One-line command

Grant "Send on behalf" permission

Set-Mailbox <Mailbox_Name> -GrantSendOnBehalfTo <User_Alias>

Grant "Send-As" permission

Add-ADPermission <Mailbox_Name> -ExtendedRights Send-As -user <User_Alias>

Grant "Full mailbox access" permission

Add-MailboxPermission <Mailbox_Name> -AccessRights FullAccess -user <User_Alias>

ActiveSync, OWA, MAPI, UM, IMAP and POP Features on a Mailbox

The following features can be disabled, enabled, and configured by using either the Exchange Management Console or the Exchange Management Shell:

  • ActiveSync

  • Outlook Web Access (OWA)

  • MAPI

  • Unified Messaging (UM)

The following features can be enabled or disabled only by using the Exchange Management Shell:

  • IMAP

  • POP

To enable, disable, or configure ActiveSync, OWA, and MAPI features by using the Exchange Management Console, click the feature on the Mailbox Features tab in the mailbox properties, and then click Enable, Disable, or Properties.

To enable or disable UM for a mailbox in the Exchange Management Console, right-click the mailbox name, click Enable Unified Messaging or Disable Unified Messaging and then follow the steps in the wizard that starts.

To enable ActiveSync, OWA, MAPI, and UM by using the Exchange Management Shell, use the following one-line command.

Action One-line command

Enable ActiveSync, OWA, MAPI and UM

set-CASMailbox <Mailbox_Name> -MobileSyncEnabled:$True -OWAEnabled:$True -MAPIEnabled:$True -PopEnabled:$True -ImapEnabled:$True
Enable-UMMailbox <Mailbox_Name> -UMMailboxPolicy testumpolicy -Extensions 12345

Policy Support for a Mailbox

You can use Mailbox Policies to apply the same settings to recipients. The following mailbox policies can be applied:

  • Unified Messaging

  • Managed Folder

  • ActiveSync

Note

Recipient policies that are used in Exchange 2003 still exist. However, they are now named E-mail Address Policy. E-mail Address Policy is not discussed in this topic.

To configure mailbox policies by using the Exchange Management Console, you must select the policy that you want to configure on the Mailbox Settings tab in the properties of a mailbox, and the select Properties. You can then configure the mailbox policy.

To complete the same action by using the Exchange Management Shell, use the following one-line command.

Action One-line command

Configure Mailbox Policy

set-Mailbox <Mailbox_Name> -ManagedFolderMailboxPolicy "Inbox JunkEmail Policy" -RetentionHoldEnabled:$True -StartDateForRetentionHold "<Month/Day/Year Time AM_or_PM>" -EndDateForRetentionHold "<Month/Day/Year Time AM_or_PM>"

Bulk Management

The management of individual objects is a straightforward process when you use the Exchange Management Console. However, when you must manage many objects at one time (bulk management), the use of one-line commands in the Exchange Management Shell is a powerful and flexible tool. Bulk management includes bulk provisioning, change management, and reporting.

Note

These procedures require that you have Administrator permissions.

The following table provides examples of one-line commands that can be used to complete specific bulk management tasks.

Action Description One-line command

Bulk create mailboxes based on a CSV file

This one-line command creates mailboxes for all team members listed in an Avalanche.csv file, which contains NHL Avalanche team roster information with the following column format:     Pos,No,Player,Age,Ht,Wt,Born,Exp,Birth City

$password = Read-Host "Enter password" -AsSecureString
import-csv Avalanche.csv | foreach {new-mailbox -alias "avalanche$($_.No)" -Name $_.Player -password $password -database "Mailbox Database" -org Users -UserPrincipalName "avalanche$($_.No)@example.com"}

Bulk create several storage groups with one message database for each storage group

In this one-line command, <nn> is a placeholder for the number of storage groups to create.

1..<nn> | foreach {new-StorageGroup SG_$_ -server <server> | new-MailboxDatabase MBDB}

Bulk create several mailboxes for a mailbox database

In this one-line command, <nn> is a placeholder for the number of mailboxes to create.

$password = Read-Host "Enter password" -AsSecureString
1..<nn> | foreach { new-Mailbox -alias "user$_" -name "User $_" -password $password -database "Mailbox Database" -org Users -UserPrincipalName "user$_@example.com" }

Bulk change mailbox settings

This one-line command changes the department name on all mailboxes.

Get-Mailbox | Set-User -department "New Dept"

Bulk change mailbox settings

This one-line command changes the department name on mailboxes where the user's name contains string "jared".

Get-Mailbox *jared* | Set-User -department "New Dept"

Bulk change mailbox settings

This one-line command changes the department name on mailboxes stored on the specified database.

Get-Mailbox -database "Mailbox Database" | Set-User -department "New Dept"

Bulk change mailbox settings

This one-line command sets the storage quota for all mailboxes in an office (using $OfficeName variable).

$OfficeName = "Boston"
get-mailbox -filter {office -eq $OfficeName } | set-Mailbox -UseDatabaseQuotaDefaults:$false -IssueWarningQuota 800MB -ProhibitSendQuota 900MB -ProhibitSendReceiveQuota 1GB

Reporting

Use one-line commands in Exchange Server Shell to generate reports that you can then use to help manage Exchange Server. The following table provides examples of one-line commands that can be used to report specific information.

Action One-line command

Export information about all mailboxes to a CSV file

get-mailbox | export-csv export.csv

Export storage quota of all mailboxes in an office (using $OfficeName variable)

$OfficeName = "<Office_Name>"
get-mailbox -filter {Office -eq $OfficeName } | select name,office, *quota | sort name | export-csv export.csv

View mailbox statistics for all mailboxes on the current server, including storage size

get-MailboxStatistics | select DisplayName, TotalItemSize, TotalDeletedItemsize, DatabaseName | format-table

More Information

For more information about recipient management using one-line commands in Exchange Server Shell, view the topic Recipient Management Using One-line Commands in Exchange Management Shell (PART 2).

For more information about how to use the Exchange Management Console to complete recipient management actions, view the topic Recipient Management Using the Exchange Management Console.

For more information about Mailboxes, view the topic Mailbox.