The Exchange Management Shell
makes common mailbox management tasks such as adding, modifying, moving,
and deleting mailboxes simple. The flexibility of EMS enables the
administrator to easily perform bulk 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 mailbox for an existing AD user or
InterOrgPerson using the interactive shell, simply enter:
and answer the prompts
for the missing parameters:
Supply values for the following parameters:
Identity: companyabc\claire
The following example
creates a mailbox for the existing user Jason in the DB14 mailbox
database:
Enable-Mailbox "companyabc\jason" -database "DB14"
Note
The -Database is
an optional parameter. If none is specified, the mailbox will be moved
to a random database.
The next example
demonstrates using EMS to create 1,000 users in AD and create mailboxes
for each user in the Test Mailbox database. This single-line cmdlet is
useful in lab scenarios.
1..1000 | ForEach {net user "user$_" MyPassword=01 /ADD /Domain; enable-mailbox
"user$_" -database "test mailbox"}
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 accept only 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 prohibit send quota for all
user mailboxes at 2GB:
get-Mailbox | set-Mailbox -ProhibitSendQuota 2gb
In the following 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 5MB:
get-Mailbox -OrganizationalUnit "Test Users" | set-Mailbox -MaxSendSize 5mb
Moving Mailboxes
Using EMS
Moving mailboxes
with the Exchange Management Shell in Exchange Server 2010 is a bit
different than it was in previous versions. The move-mailbox cmdlet has
been replaced with four new cmdlets: New-MoveRequest, Get-MoveRequest,
Set-MoveRequest, and Remove-MoveRequest.
New-MoveRequest | Begins
the process of a mailbox move. |
Get-MoveRequest | Gets the status of an
in-process mailbox move. |
Set-MoveRequest | Changes move request
options after the move has begun. |
Remove-MoveRequest | Cancels an ongoing
mailbox move. |
When the Move-Mailbox
cmdlet is used to move a mailbox, the cmdlet logs into both the source
database and the target database and moves the content from one mailbox
to the other mailbox. The move process can take several hours to
complete, depending on the mailbox size.
The new MoveRequest
cmdlets perform an asynchronous mailbox move because they do not
perform the actual move. A new Exchange Server 2010 service running on
an Exchange Server 2010 Client Access called the Mailbox Replication
Service (MRS) actually performs the move. The New-MoveRequest cmdlet simply sends the request to the Mailbox
Replication Service. The benefit of using the service is that it enables
the administrator to manage mailbox moves from EMS after the move
request has been made.
The Set-MoveRequest cmdlet provides the capability to change the
options of an in-progress mailbox move. The Get-MoveRequest cmdlet reports the current status of a mailbox
move.
The Remove-MoveRequest cmdlet enables the administrator to cancel a move that is in
progress. A move can be canceled at any time before the move completes.
If a move is canceled, the mailbox remains on the source server and
database.
A simple move of a
mailbox from one database to another on the same server is accomplished
like this:
New-MoveRequest claire –TargetDatabase "accounting database"
Note
The TargetDatabase is
an optional parameter. If none is specified, the mailbox will be moved
to a random database.
EMS knows the names 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:
New-MoveRequest claire –TargetDatabase "SERVER2\accounting database"
Note
EMS will accept only
the server name in the TargetDatabase parameter if there is more than
one database with the same name in the same organization.
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.com forest to the expta.com forest:
New-MoveRequest companyabc\claire -Remote –RemoteHostName mbx1.expta.com