The Exchange Management Shell makes common mailbox
management tasks such as adding, modifying, moving, and deleting
mailboxes simple. The flexibility of EMS allows the administrator to
easily perform tasks that would require much more time and labor if
done from the Exchange Management Console.
Creating Mailboxes with EMS
Mailboxes
can be created with EMS singly or in bulk. They can be created using
the interactive command prompt or by specifying the required parameters
from the command line. To enable a malbox using the interactive shell,
simply enter:
and answer the prompts for the missing parameters:
Supply values for the following parameters:
Database: mailbox store
Identity: companyabc\jason
The following example creates a mailbox for the existing user Jason in Mailbox Store 3 on SERVER1:
Enable-Mailbox "companyabc\jason" -database "SERVER1\mailbox store 3"
The next example demonstrates
using EMS to create 1,000 users in Active Directory and create
mailboxes for each user in the Test Mailbox Store on SERVER3. This
single-line cmdlet is very useful in lab scenarios.
1..1000 | foreach {net user "user$_" MyPassword=01 /ADD /Domain; enable-mailbox
"user$_" -database "SERVER3\test mailbox store"}
Doing this same operation using VBScript would take many more lines of code and require much more development time.
Modifying Mailboxes with EMS
Mailbox
attributes can easily be modified using EMS, as well. The following
example modifies the mailbox for user Jason in the default domain to
only accept emails from [email protected]:
set-Mailbox jason -AcceptMessagesOnlyFrom [email protected]
It
is just as easy to make changes on many mailboxes at the same time
using pipelining. Consider the following example that sets the mailbox
quota for all user mailboxes at 250MB:
get-Mailbox | set-Mailbox -StorageQuota 250mb
In this example, we use the –OrganizationalUnit parameter of the Get-Mailbox cmdlet to set the maximum message size that users in the Accounting OU can send to 10MB:
get-Mailbox -OrganizationalUnit "Test Users" | set-Mailbox -MaxSendSize 10mb
Moving Mailboxes Using EMS
Moving
mailboxes with the Exchange Management Shell is very easy and powerful.
A simple move of a mailbox from one database to another on the same
server is accomplished like this:
Move-Mailbox Claire –TargetDatabase "accounting database"
EMS
knows the name of all the databases in the organization. If there is
more than one database with the same name, EMS moves the database to
the first alphabetic server with that database name. To target a
specific server, explicitly name the server in the TargetDatabase parameter. For example:
Move-Mailbox Claire –TargetDatabase "SERVER2\accounting database"
More complex moves are
achieved just as easily from the Exchange Management Shell command
line. In the following example, the mailbox is moved from the
companyabc.org forest to the companyabc.com forest.
Move-Mailbox -SourceForest company123.org -TargetForest companyabc.com–targetDatabase "mailbox store 9" company123\lilly
Of course, a realm trust must be established prior to moving the mailbox.
Disabling Mailboxes with EMS
Administrators
do not delete mailboxes in Exchange 2007—they disable them. Disabling a
mailbox detaches the mailbox of an existing user or inetOrgPerson and
removes all of that object’s Exchange attributes from Active Directory.
The mailbox is truly deleted by Exchange during the online maintenance
cycle after exceeding the retention time.
The following example disables a mailbox of a user in the companyabc.com domain:
Disable-Mailbox companyabc\claire
The next example shows how to delete all the mailboxes in the “Test Database” mail store so that it can be decommissioned:
get-Mailbox -database "test database" | disable-Mailbox –whatif
The –WhatIf
switch in the preceding example runs the task in Read-only mode,
allowing the administrator to see what would happen by running this
command.
Another related command is Remove-Mailbox.
This command removes the user account that is associated with a
particular mailbox in Active Directory and processes the associated,
disconnected mailbox as directed by the specified parameters.
Remove-Mailbox -MailboxDatabase "Sales Database" "companyabc\storage group 2\jason"