BACKGROUND IMAGE: iSTOCK/GETTY IMAGES

This content is part of the Essential Guide: The essential guide to PowerShell in Exchange
Manage Learn to apply best practices and optimize your operations.

PowerShell essentials for Exchange 2010 administrators

Microsoft has made it clear PowerShell is going to be the administrative tool of choice moving forward. Familiarize yourself with basic syntax or get left behind.

Exchange admins need to know how to work within PowerShell. For one, many administrative functions can only be performed through the Exchange Management Shell, as opposed to the Exchange Management Console. Second, Microsoft has made it clear that PowerShell will be the administrative tool of choice going forward. Familiarize yourself with basic Exchange Management Shell functionality before you fall too far behind.

Knowing which PowerShell command to use
When starting out with PowerShell, knowing which commands to use can be daunting. Thankfully, Microsoft provides a simple and intuitive way to discover which commands can be used in any given situation.

Let’s say you want to delete a user’s mailbox. Delete-Mailbox might be your first guess, but it is not a valid PowerShell command. Enter Get-Command to find out which operations can be performed on Exchange mailboxes. For example, you can use a command similar to the following:

Get-Command –Noun Mailbox

Note: Get-Command can also be used with the –Verb switch.

You should also know that Exchange Server uses a number of PowerShell cmdlets that are not available through Windows PowerShell. You can learn about all these commands on the Microsoft TechNet site.

Hidden properties
One of the most important things Exchange Server admins need to know about the Exchange Management Shell (EMS) is that many cmdlets are designed to hide the bulk of the available information.

Take the Get-Mailbox cmdlet for example; Exchange uses dozens of different mailbox attributes, yet when you enter the Get-Mailbox cmdlet, the only attributes you’ll see are Name, Alias, ServerName and ProhibitSendQuota. If you want to see a full list of the attributes available, use the following command:

Get-Mailbox | Get-Member –MemberType *Property | Select-Object Name

Remember that even though I’m using Get-Mailbox as an example, this command works with almost any noun, as long as the noun works with Get. For example, you can start the command with Get-User, Get-Group or Get-Host. You can also use Get-Command –Verb Get to determine which commands can be used with the verb Get.

So what exactly you can do with a list of properties for an object (mailbox properties, user properties, etc.)? You can use the properties to customize a command’s output. For example, if you’d like to see a list of user mailboxes, as well as the server that each mailbox resides on, you can do so with the following command:

Get-Mailbox | FL Name, ServerName

Note: FL is an abbreviation for Format-List. You can also use FT or Format-Table.

Limiting result size
While the ability to display mailbox information through PowerShell is great, larger Exchange organizations might find that their number of mailboxes makes the described techniques impractical. Fortunately, there are ways to narrow the list.

One way is to use the ResultSize option. The ResultSize switch lets you specify how many results you want to view. For example, if your organization has 10,000 mailboxes, but you only want to see the first 10, you can set the result size to 10.

Simply append the ResultSize switch and the desired number of results. For example, if you only want to see 10 mailboxes, use the following command:

Get-Mailbox –ResultSize 10

The ResultSize switch can be combined with the other options I’ve shown you as well. For example, if you want to see a list of the first twenty five mailboxes and the server they reside on, then use the following command:

Get-Mailbox –ResultSize 25 | FL Name, ServerName

Another way to narrow the result list is to filter it by a mailbox attribute. This is done using the Where option and an operator. For example, suppose you want to generate a list of all of the mailboxes that reside on a mailbox server Lab-E2K10. To do so, use the following command:

Get-Mailbox | Where-Object {$_.ServerName –eq ‘Lab-E2K10’}

In this case, the property -- ServerName -- is compared against a value -- Lab-E2K10. The –EQ portion of the command is the operator; it stands for “equals.” Some of the other operators at your disposal are as follows:

-LT          Less than
-LE          Less than or equal to
-GE         Greater than or equal to
-GT         Greater than
-NE         Not equal to

ABOUT THE AUTHOR:
Brien Posey is an eight-time Microsoft MVP with two decades of IT experience. Before becoming a freelance technical writer, Brien worked as a CIO at a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the nation’s largest insurance companies and for the Department of Defense at Fort Knox.

This was last published in April 2012

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchSQLServer

SearchEnterpriseDesktop

SearchVirtualDesktop

Close