In this article, we will talk about EMS commands and how to format the output from your commands.
In part one of this three-part tip series, you learned about some of the terminology associated with the Exchange Management Shell (EMS) that Microsoft has introduced in Exchange 2007. In this, part two, you will learn how to use EMS commands and how to format the output from your commands. You'll also get a quick look at piping your commands through to other commands.
The most important thing you can learn about the EMS is how to get help. And, the EMS offers you a couple of ways to do so. The first way is to use either "help cmdlet" or "cmdlet -?". This causes the EMS to provide you with the abbreviated syntax and usage information for the specified cmdlet, as shown in Figure A.
|Abbreviated help for the get-casmailboxcmdlet.|
Notice that the abbreviated help doesn't give you any detail about the various parameters except to specify what kind of data--a string, number, etc.--is expected. Sometimes, that’s just not enough information. So the EMS provides a way to get more detailed help. Use the command "help cmdlet -detailed" option to get multiple pages of help that outline exactly what is expected for each parameter. You can also get more technical help by using "help cmdlet -full." This command provides you with technical information for each parameter. For example, the full option will tell you whether a particular parameter is required, whether it will accept pipelined input and whether you can use a wildcard in the parameter value.
You’ve just seen one cmdlet, get-casmailbox. When run with no parameters, the get-casmailboxcmdlet returns a list of mailboxes in the current Exchange organization along with some general information, such as whether or not OWA, POP and IMAP are enabled for each mailbox. Figure B gives you a look at this output.
|The get-casmailbox command returns organizational mailbox information.|
Now, there will probably come a time when you want to be able to manipulate a particular mailbox object property, such as disabling a user’s ability to POP mail from your servers. Here is a command that will disable POP3 mailbox access for a specific user:
set-CASMailbox -identity email@example.com -POPEnabled:$false
In this example, the "identity" parameter is used to specify the exact object that is to be manipulated. However, since the identity object, in this case, firstname.lastname@example.org, is required for this command, you don’t need to specify "-identity". In other words, the following commands would be functionally equivalent to the example above:
set-CASMailbox email@example.com -POPEnabled:$false
set-CASMailbox -POPEnabled:$false firstname.lastname@example.org
For some cmdlets, you also don’t need to specify some of the parameter names, but can just put parameter values on the command line in a specific order. Personally, I don’t like this approach as it’s too error-prone and results in very poor readability.
After you run the set-casmailboxcmdlet, you can issue get-casmailbox to see if your changes have taken effect.
Speaking of get-casmailbox, you might want to gather other information from user mailboxes beyond just what services are enabled and disabled, as you saw earlier. By piping your command through the format-list command, you can get the complete list of possible parameters that you can use for output. Be careful with format-list, especially against large data sets. This command, unless you actively limit its output, will show you every parameter for every mailbox, which, if you have a ton of mailboxes, could take quite some time! Figure C. gives you a look at the output for a single mailbox.
|There are a number of parameters you can get in your output.|
The command I used to get the output in Figure C was:
get-casmailbox | format-list
Note the use of the bar between the two cmdlets. In part one of this tip, I talked about pipelining, or piping. This symbol is commonly called the pipe character and, in EMS, is used to present the result of one command to another command for further processing. In this example, the full output from the get-casmailbox command is passed to the format-list command, which is responsible for--wait for it--formatting the command's output in list form versus the default tabular form. Format-list has an alias -- "fl".
Obviously, getting all of this output isn't always desirable either. While format-list is a great way to get a complete list of available display parameters, it’s not always practical to list every single bit of information. Therefore, you can pipe the results of get-casmailbox to yet another cmdlet--select. The select command takes a list of parameter names and displays just that information rather than the every field.
Here’s a look at how the select cmdlet works:
Get-casmailbox | select identity,guid
This command pipes the display results of the get-casmailbox to the select command where just the object’s GUID and object identity are displayed, as shown below in Figure D.
|This command limits the output to just the two fields specified.|
This output can get unwieldy very quickly, though. Take a look at Figure E.
|This output is pretty truncated.|
Note that this output in Figure E is severely truncated almost to the point of being unusable. So, what can you do? Simple: Make it a list instead of a table by piping this into format-list, like so:
get-casmailbox | select identity,guid,samaccountname,primarysmtpaddress | fl
|This output is much easier to read.|
This ends this primer to the Exchange Management Console. In many of my future tips, I’ll be focusing on getting work done in the EMS, so this is not the last you will see on this topic.