The Exchange Management Shell shares the
same verb-noun syntax as PowerShell. This provides a consistent set of
commands to learn and understand within the command environment.
Understanding the Verb-Noun Construct
EMS
uses a strict verb-noun naming constraint for all of its cmdlets. The
verb is separated from the noun with a hyphen. For example, the cmdlet get-mailbox returns all of the mailbox objects in the organization.
Common
verbs include add, clear, disable, enable, export, get, import, move,
new, remove, set, test, update, and write. As in the English language,
there are many more nouns than verbs. There is a very high level of
verb reuse to provide a consistent, predictable user experience.
Examples of nouns used in EMS are mailbox, mailboxserver,
ExchangeServer, TransportSettings, GlobalRule, object, service, and so
on.
Walking Through Cmdlets in EMS
Some
cmdlets offer many different switches and parameters. If administrators
are not comfortable entering all the parameters for a cmdlet in one
line, they can enter as much as they want, press Enter, and EMS will
prompt for the rest. This provides an easy way to run cmdlets that are
not often used and that don’t necessarily need to be saved for reuse.
For example, enter move-Mailbox and EMS prompts for the missing required parameters.
Cmdlet move-Mailbox at command pipeline position 1
Supply values for the following parameters:
TargetDatabase: Mailbox Store 2
Identity: Amy C. Guillet
This is the same as entering the following single line at the EMS command line:
Move-Mailbox "Amy C. Guillet" –Targetdatabase "Mailbox Store 2"
Getting Help with EMS
The
Exchange Management Shell features a QuickStart guide that gives a
quick tutorial on common commands and syntax. It provides common tasks
and options, tips and tricks, recipient management examples, storage
management examples, transport configuration examples, policy
configuration, and server management examples. This is presented in a
Hypertext Markup Language (HTML) page by simply typing Quickstart at the console.
The
Exchange Management Shell includes two basic types of help—command help
and conceptual help. Both types can be accessed from the console using
the Get-Help cmdlet, which also uses the alias help.
To retrieve a list of all available help topics, simply type help *. To get help with a specific cmdlet, type help cmdlet-name. For example, help move-databasepath displays the purpose of the cmdlet, all required and optional parameters, return variables, and examples of its use.
By
default, some information appears in the console window as one long,
scrolling topic. To view the information a single page at a time, pipe
the results to more. For example, Get-ExCommand | More displays all the Exchange-specific cmdlets in EMS, one page at a time.
Using Pipelining in EMS
Pipelining
is the key to the power of EMS. It uses the output of one cmdlet to run
through another cmdlet using the “|” (pipeline) operator. Pipelining
provides bulk management changes. To understand this concept, examine
this example:
Get-mailbox –server SERVER1 | move-mailbox -targetdatabase "UMSERVER\Mailbox Database 1"
The
first part of the line, the part before the “|” operator, tells EMS to
get all the mailbox objects on server SERVER1. It then sends, or pipes,
the resulting set of objects to the next command, which instructs it to
move them to Mailbox Database 1 on the server UMSERVER.
Another way of saying it is that one process output is consumed by another and another. Consider another example:
get-mailbox | where-object { $_.name -like "amy*" } | set-Mailbox -MaxSendSize 10mb
In this example, the get-mailbox cmdlet returns all the mailbox objects on all servers in the organization. This collection is piped through the where-object filter cmdlet that filters out the mailbox objects to only include mailboxes with names beginning with “amy.” The “$_” variable equates to “this object.” These objects, in turn, are piped through the set-Mailbox cmdlet to pass the parameter –MaxSendSize and set the value to 10Mb.
Note that EMS is not case sensitive and that it understands that 10MB equates to 10,240,000 bytes. In this example, the get-mailbox cmdlet produces a result, the where-object consumes it and produces another result, and this result is consumed by the set-mailbox cmdlet to set the new value.
Using the WhatIf and Confirm Parameters
There
are times when the administrator will write a simple or complicated
script in EMS and wonder what results it will produce. Some cmdlets
support the –WhatIf–Confirm parameters. The –WhatIf parameter informs the administrator what action the script would take and the –Confirm parameter prompts for confirmation before taking action. and
For
example, suppose the administrator wants to retire Mailbox Store 5 on
SERVER1, and move all the existing mailboxes from the the current
database to Mailbox Store 2 on UMSERVER. The administrator could use
the following command:
Get-mailbox –database "SERVER1\Mailbox Store 5" | move-mailbox –targetDatabase "UMSERVER\Mailbox Store 2
By adding the –WhatIf parameter, the following result is output to the console for each mailbox:
What if: Performing operation "move-Mailbox" on Target "Move mailbox for:
Administrator ([email protected]) to Database: Mailbox Database
2,09014bc6-f977-4961-b4eb-8829fb13e5d6. The operation can take a long time and the
mailbox will be inaccessible until the move is complete".
This
allows the administrator to easily see what operation would be
performed by the script. If the results are as expected, the
administrator presses the up arrow to recall the last typed line, and
removes the –WhatIf parameter to execute the script.
If the administrator adds the –Confirm parameter, the following is output to the console:
Are you sure you want to perform this action?
Performing operation "move-Mailbox" on Target "Move mailbox for: Administrator
([email protected]) to Database: Mailbox Database 1,09014bc6-f977-4961-
b4eb-8829fb13e5d6. The operation can take a long time and the mailbox will be
inaccessible until the move is complete".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):
Entering
“Y” processes this move, “A” processes all moves, “N” skips this move,
“L” cancels further processing, and “S” suspends processing and returns
the administrator to the console. Typing “exit” resumes processing.