The essential guide to PowerShell in Exchange
A comprehensive collection of articles, videos and more, hand-picked by our editors
The Exchange Management Shell (EMS) allows administrators to manage Exchange Server 2007 from the command line. Although most administration tasks can be performed through Exchange 2007's graphical user interface, the Exchange Management Console (EMC), there are some tasks that cannot be accomplished through the console. Here, contributor Brien Posey demystifies the Exchange Management Shell. He explains the basic syntax structure used...
to perform common commands such as the Get Command.
When trying to understand the purpose of the Exchange Management Shell in Exchange Server 2007 and the ability to perform tasks from the command line, consider the Windows Control Panel. The majority of options available to you through the Control Panel directly affect various registry values. When you implement a setting through the Control Panel, you're editing the system registry. Countless registry settings are only available by running the Registry Editor.
Exchange Server 2007 works in a similar manner. The Exchange Management Console exposes most common Exchange-related settings, but there are several settings that you can't access without using the Exchange Management Shell.
Even if you're familiar with DOS and comfortable working in a command-line environment, the Exchange Management Shell may be intimidating at first. There are multiple commands available, many of which seem quite complex. After working with the Exchange Management Shell further, however, using it isn't too difficult.
Although it's possible to perform all administrative activities directly through the Exchange Management Shell, I don't recommend doing so. I prefer to use the Exchange Management Console and only use the Exchange Management Shell in situations that make using the console impractical. Even if you don't plan to use the Exchange Management Shell, you still should familiarize yourself with how it works and some basic syntax.
The commands used within the Exchange Management Shell follow a verb-noun format; it uses 10 primary verbs (Table 1). This list isn't all-encompassing. Other verbs, such as Export and Connect, are used less frequently.
|Get||Returns information about the specified object|
|Set||Modifies properties of the specified object|
|Remove||Deletes the specified object|
|Test||Tests the component that you specify|
|Enable||Enables the specified object|
|Disable||Disables the specified object|
|Install||Installs the specified Exchange Server feature|
|Uninstall||Removes the specified Exchange Server feature|
|New||Creates a new Exchange Server object|
|Move||Moves a specified object from one container to another|
Table 1. Primary verbs and commands of the Exchange Management Shell.
Verbs are always followed by a dash and a noun. The noun typically refers to an Exchange object; additional parts of the command may refer to individual attributes of that object.
T he Get command in the Exchange Management Shell lets you retrieve information about a specified object. The most familiar Exchange Server object is likely the mailbox. Not surprisingly, the Get command can be used in conjunction with the word Mailbox to retrieve information about a mailbox. If you enter the Get-Mailbox command, you'll see a screen similar to that shown in Figure 1.
The first thing that you may notice on this screen is the yellow text. When the Exchange Management Shell displays command output, warnings are displayed in yellow and errors are displayed in red. In this example, warning messages indicate that mailboxes are corrupt; however, this warning is incorrect.
When you issue the Get-Mailbox command without including any additional parameters, the Exchange Management Shell retrieves information about every mailbox in the entire Exchange Server 2007 organization, regardless of the server on which a mailbox resides. In this particular case, the two mailboxes for which warnings were displayed reside on an Exchange 2003 server.
Exchange Server 2007 uses some mailbox attributes that didn't exist in Exchange Server 2003. When you try to display those mailboxes through the Exchange Management Shell, Exchange 2007 thinks that the mailboxes are corrupt because they are "missing" attributes. Not every Exchange 2003 mailbox appears as corrupt, though. Whether or not the Exchange Management Console lists an Exchange 2003 mailbox as corrupt depends on a few factors.
If you ignore the warning messages, there are two problems with information that the Get-Mailbox command provides.
- The command lists every mailbox in the entire organization. Because I have a small Exchange organization, all mailboxes fit on a single screen. If you were to issue the Get-Mailbox command in a large organization, the Exchange Management Shell might pull mailbox information for an hour or two. This would be too much information for a single screen and wouldn't be useful.
- The Get-Mailbox command only displays the mailbox name, its alias, the name of the server that the mailbox resides on and the mailbox quota. If you look at a mailbox's properties sheet in the Exchange Management Console, there are many more mailbox attributes than those being displayed. The Exchange Management Shell limits displayed attributes to prevent information overload.
In its most basic form, the Get-Mailbox command is useful for displaying a quick mailbox summary in a small organization. You can use additional parameters in conjunction with the verb-noun syntax. Typically, however, when additional parameters are used in conjunction with the Get command, they narrow down results or display specific information.
Results that the Get-Mailbox command produces can be changed. For example, to limit the results to mailboxes residing on a specific server, use the following command:
Get-Mailbox –Server servername
Warning messages don't appear in Figure 2 because we're looking at mailboxes residing on an Exchange 2007 server only.
It's helpful to filter results based on individual attributes. The real issue is knowing which attributes are available. Microsoft offers information related to various commands, including a useful KnowledgeBase article on the Get-Mailbox command. You can also use the -? parameter. Entering Get-Mailbox -? prompts Exchange to display the command's full syntax.
A PRIMER ON THE EXCHANGE 2007 EXCHANGE MANAGEMENT SHELL
Part 1: How to use the Exchange Management Shell command syntax
Part 2: How to use the Exchange Management Shell Filter command
Part 3: Control query results with the EMS Format command
Part 4: How to test Exchange Management Shell commands
ABOUT THE AUTHOR:
Brien M. Posey, MCSE
Brien M. Posey, MCSE, has previously received Microsoft's MVP award for Exchange Server, Windows Server and Internet Information Server (IIS). Brien has served as CIO for a nationwide chain of hospitals and was once responsible for the Department of Information Management at Fort Knox. As a freelance technical writer, Brien has written for Microsoft, TechTarget, CNET, ZDNet, MSD2D, Relevant Technologies and other technology companies. You can visit Brien's personal Web site at http://www.brienposey.com.