Using the Exchange Management Shell

The Exchange Management Shell, shown in Figure 10-9, is based on Microsoft Windows PowerShell, which provides a powerful command-line interface for executing and automating administrative tasks. With the Exchange Management Shell, you can manage every aspect of Exchange Server 2007, including enabling new e-mail accounts, configuring store database properties, and just about every other management task associated with Exchange Server 2007.

Cc505910.figure_C10623503_9(en-us,TechNet.10).png

Figure 10-9 The Exchange Management Shell

In fact, you can use the Exchange Management Shell to perform every task available in the Exchange Management Console and a number of tasks that cannot be performed in the Exchange Management Console. It helps to think of it this way: the Exchange Management Console provides a graphical interface for most of the functionality of the Exchange Management Shell. When you run a command in the Exchange Management Console, the Exchange Management Shell is actually called to perform the command. When you perform a command in the Exchange Management Console, the graphic interface often even shows you the associated shell command, as shown in Figure 10-10.

Cc505910.figure_C10623503_10(en-us,TechNet.10).png

Figure 10-10 Viewing shell commands from the Exchange Management Console

So why use the shell instead of the console? Aside from the fact that some commands (such as those used to manage public folders) are only available as shell commands, the shell also offers a flexibility that can speed up and simplify common operations. For example, with a single shell command, you can get a list of recipients, filter that list according to a set of criteria, and then perform a function on only the filtered list of recipients.

Note

The Exchange Management Shell also provides a robust and flexible scripting platform that can reduce the complexity of current Microsoft Visual Basic scripts. Tasks that previously required many lines in Visual Basic scripts can now be done by using as little as one line of code in the Exchange Management Shell. The Exchange Management Shell provides this flexibility because it does not use text as the basis for interaction with the system, but uses an object model that is based on the Microsoft .NET platform. This object model enables the Exchange Management Shell cmdlets to apply the output from one command to subsequent commands when they are run.

To open the Exchange Management Shell, follow these steps:

  1. Click Start, point to All Programs, and then point to Microsoft Exchange Server 2007.
  2. Click Exchange Management Shell.

More Info

This section is intended to introduce you to the basics of using the Exchange Management Shell. Throughout this book, you find specific examples of using shell commands to complete administrative tasks. For more information on using the Exchange Management Shell, please consult the Exchange Server 2007 Help files. Help includes detailed advice on using advanced options such as WhatIf and comparison parameters, command output, shell variables, structured data, and scripting.

Understanding Cmdlets

At first glance, the shell may seem similar to other command-line interfaces with which you may be familiar. However, after working with the shell for just a few minutes, you see that there are dramatic differences.

In the Exchange Management Shell, a cmdlet is the smallest unit of functionality. A cmdlet is roughly analogous to a built-in command in other types of shells. You type cmdlets directly into the shell interface.

All cmdlets consist of at least two parts:

  • A verb The verb represents the action of the command. An example of a verb is get, which is used to retrieve information about an object. Table 10-1 lists the most common verbs used in the Exchange Management Shell.
  • A noun The noun represents the recipient of the verb’s action. An example of a noun would be an object in the Exchange organization such as a mailbox server. The noun in this case would be MailboxServer.

Cmdlets always contain a verb and a noun separated by a hyphen. To continue the previous example, the cmdlet for getting information about a mailbox server would be:

Get-MailboxServer

Table 10-1 Common Verbs in the Exchange Management Shell

Cc505910.table_C10623503_1(en-us,TechNet.10).png

Obviously, you can’t do too much with just a verb and a noun. For example, the cmdlet Get-MailboxServer doesn’t provide enough information for the shell to do anything. You need to specify which mailbox server and likely what information you want to get. You provide this extra information through parameters. Parameters provide information to the cmdlet, either identifying an object and its attributes to act on, or controlling how the cmdlet performs its task.

To use a parameter, type a space following the verb-noun pair and then type the parameters you need. The name of the parameter is always preceded by a hyphen (-) and the use of parameters follows this syntax:

Verb-Noun –ParameterName <ParameterValue>

For example, to get information about a specific mailbox server (say, a server named contoso-exsrv1), add the identity parameter to the cmdlet, like this:

Get-MailboxServer –Identity contoso-exsrv1

Note

You can find a complete reference of cmdlets including parameters available in the Exchange Management Shell in the Exchange Server 2007 Help files. The cmdlets used to perform various activities are included throughout this book.

Getting Help

Obviously, it is difficult to remember all the verbs, nouns, and parameters available in the Exchange Management Shell. Fortunately, there are several ways to get help right within the shell.

Help Cmdlets

Three help cmdlets are available in the shell to help you find the information you need to perform tasks: Get-Help, Get-Command, and Get-ExCommand.

When you use the Get-Help command by itself (that is, when you type no parameters with it), the shell provides basic information about using the shell, as shown in Figure 10-11.

Cc505910.figure_C10623503_11(en-us,TechNet.10).png

Figure 10-11 Getting help in the Exchange Management Shell

You can also use several parameters along with the Get-Help cmdlet to get more focused help on the task you’re trying to perform. For example, you can use the name of a cmdlet as a parameter to get help on using that cmdlet. Typing the following gives you help on using the Get-MailboxServer cmdlet:

Get-Help Get-MailboxServer

You can even go a step further by adding parameters to further narrow the help you receive. Following the Get-Help <cmdlet> syntax, you can add the following parameters:

  • Get-Help <cmdlet> -Full Provides full help on the specified cmdlet.
  • Get-Help <cmdlet> -Parameter <parametername> Provides just the help view for the specific parameter of the cmdlet you name.
  • Get-Help <cmdlet> -Examples Provides just the examples portion of the help view for the cmdlet you name.

You can use the Get-Command cmdlet by itself (no parameters) to view a list of all commands available in the shell. You can also add –noun and –verb parameters to the Get-Command <commandname> syntax to view all cmdlets with the specified noun or verb. Also, you can use the Get-ExCommand cmdlet to return all the cmdlets that are specific to Exchange Server 2007. Otherwise, the Get-Excommand cmdlet works just like the Get-Command cmdlet.

Tab Completion

Tab completion helps reduce typing when using the shell. When you have typed a partial cmdlet name, just press Tab, and the Exchange Management Shell completes the cmdlet name if it finds a matching cmdlet. If it finds multiple matching cmdlets, the shell cycles through each cmdlet name as you keep pressing Tab. When you use tab completion with cmdlet names, you must supply at least the verb and the hyphen (-).

For example, you can use Tab completion to quickly view the nouns associated with the get verb. Just type Get- at the prompt and then keep pressing Tab to cycle through the available nouns you can use with get.

For another example, if you cannot remember (or just didn’t want to type) a full cmdlet such as Get-MailboxServer, you can type Get-Mail and press Tab to find the correct cmdlet without having to type the full name.

< Back      Next >

 

 

© Microsoft. All Rights Reserved.