PowerShell Basics in Microsoft Exchange 2010

There are many reasons why an organization would make the move to Exchange Server 2010. Features like email archiving, increased discovery capabilities, greater flexibility and the lure of anywhere access make this email solution a promising one.

However, these features are generally ones that are used to sell management on an upgrade or switch. For administrators, the PowerShell is usually a feature that gets them on board.

The PowerShell feature of Microsoft Exchange is similar to what some email administrators who worked in a UNIX-based environment are accustomed to.

Giving admins the ability to automate repetitive tasks with scripts, called cmdlets, helps save time as many find navigating through GUI menus and submenus looking for the right actions to be wasteful when the same thing can be done by running a few lines of code.

Understanding the basics

PowerShell is installed by default on Exchange 2010. To launch it you will need to be on a workstation, or server, where you have installed the Exchange Management Tools. By clicking on Start | All Programs | Exchange Server 2010, you will be presented with the Exchange Management Shell shortcut. Clicking on this icon will launch the shell for you to get started.

Cmdlets follow a pretty simple syntax. To run a command in PowerShell you simply type in the name of the cmdlet followed by a hyphen and then any parameters. The value of the parameter comes after the parameter name itself and can be wither option or required depending upon which cmdlet you are running. So an example cmdlet would look like this:

Set –Mailbox username –MaxSendSize 5mb -MaxReceive Size 10mb

The result would be to modify the user’s mailbox so that he or she could only send messages under 5mb but would allow them to receive messages up to 10mb. Of course you would need to supply an actual username.

There are times when PowerShell will ask for confirmation before the cmdlet takes the requested action. For example, if you were removing a mailbox the shell will ask you “Are you sure you want to perform this action?” followed by an explanation of what you are about to do.

While you can easily hit the Y key to confirm, or the A key to say Yes to All, you can also turn off the confirmation with the –Confirm:$false parameter.

Parameters also don’t always have to be typed out fully. You can use a shortcut by typing enough characters of the parameter name to differentiate it from any other parameters. An example of this is the –Identity parameter. A valid substitution for this can be –id since this is unique enough to meet the requirement. Since –Identity is one of the most frequently used parameters, this shortcut can be quite helpful.

Wildcards can also be used cmdlets. To use a wildcard the asterisk, “*”, is entered after the characters you select. An example of this can be seen in the following where we set the mailbox sizes for only those that start with the letter “a”:

Set –Mailbox –id a* –MaxSendSize 5mb -MaxReceive Size 10mb

The final tip to getting started in PowerShell deals with the use of single and double quotes in your scripts.

Whenever the values for your parameters require a space, the values need to be enclosed. Most commonly the single quotes would be used for this as in the following example:

Get-Mailbox -OrganizationalUnit 'yourdomain.com/Management Users/Chicago'

This cmdlet will retrieve information for all uses in the specified OU.

Double quotes are used when you expand a variable within a string:

Get-Mailbox -OrganizationalUnit “yourdomain.com/Management Users/$City”

Get yourself some help

The help system for any scripting should be your first resource if you run into trouble. When it comes to the PowerShell, help is just a command away.

Get –Help followed by the name of the cmdlet is all you need to type. If you want to get more information about the Get –Mailbox cmdlet then you would enter:

Get –Help Get –Mailbox

To get more specific information, you can use these switches:

  • -Detailed – Provides parameter descriptions and examples
  • -Examples – Provides multiple examples of how the cmdlet can be used
  • -Full – Provides you with the all the help content regarding the cmdlet

So for everything dealing with the Get –Mailbox cmdlet you would type:

Get –Help Get –Mailbox –Full

Again, all of these actions can be completed using the GUI provided with Microsoft Exchange 2010, but having a strong familiarity with the PowerShell not only allows you to get through some tasks a bit quicker, but can be a lifesaver in many circumstances.

Written by Jeff Orloff

Leave A Reply