Microsoft Exchange 2010 PowerShell Cookbook
上QQ阅读APP看书,第一时间看更新

Using command discovery through the Exchange Management Console

The Exchange Management Console simply carries out PowerShell commands in the background as you add, remove, and modify objects. One of the nice features is that most of these commands are exposed through the console, and you can use it as a tool to learn PowerShell. In this recipe, we'll look at a few ways in which you can discover which PowerShell commands are being executed when making changes in the console.

Getting ready

To use the examples in this recipe, you will need to launch the Exchange Management Console.

How to do it...

In the Exchange Management Console, highlight an item in the console tree, click on the View menu, and select View Exchange Management Console Command Log, as shown in the following screenshot:

This will bring up the Exchange Management Shell Log window, as shown in the following screenshot:

In addition to command logging, you can use the PowerShell command button when modifying the settings of an object. For example, after modifying the Office setting for a mailbox, the PowerShell command button located at the lower-left hand corner of the properties window will be enabled:

After clicking the PowerShell command button, you'll be able to view the cmdlet and the parameters that will be used to carry out the change:

How it works...

PowerShell command logging is enabled by default and will record the last 2,048 commands generated by Exchange. Each logged command shows the start and end of execution time, along with the status. You can highlight the log entry to view the command and any parameters used in the bottom window. You can go to the Action menu and modify several properties, such as stopping or starting command logging, increasing the number of commands the system should keep track of, or copying any previously run commands.

Using the PowerShell command button is also a good way to figure out the syntax for the commands being used to change a setting. Imagine that you needed to know how to write a script that would enable a custom storage quota at the mailbox level for a group of users. You could go into the properties of one mailbox and modify the storage quota setting. Before clicking Apply and OK, you can click the PowerShell command button to figure out the syntax for the command. You could then write a script based on this information that could be run against one or more mailboxes.

There's more...

In addition to PowerShell Command Logging and the PowerShell command button, the Exchange Management Console will also provide the commands used to perform a task. For example, when creating a mailbox in the console, you are taken through a wizard that allows you to configure the required settings for the mailbox. At the end of the wizard, you'll see a screen that will give you the exact command carried out by Exchange to create the mailbox, like the following:

As you can see, the final screen at the end of the New Mailbox wizard provides the command used to create the mailbox using the New-Mailbox cmdlet. All of the values entered into the previous screens have been converted to parameter values. You can click ctrl + c on this screen to copy the command used to create the mailbox.

See also

  • Understanding command syntax and parameters in Chapter 1, PowerShell Key Concepts
  • Using the help system in Chapter 1, PowerShell Key Concepts