PowerShell in Exchange 2007

PowerShell in Exchange Server 2007 PowerShell Exchange 2007 Server

PowerShell provides a command-line language for configuring your Exchange Server 2007.  Please trust me when I say that it’s easy to get started with PowerShell [try: $host].  Believe me when I say that you don’t need an in-depth knowledge of PowerShell to manage your server with simple verb-Noun phrases [try: get-Process, or get-ExchangeServer].

For future reference, take note when I say that PowerShell is as complex as VBScript, but unlike that language, you don’t need the understanding of a programmer to benefit from PowerShell [try: get-Eventlog system -newest 10].

Topics for PowerShell in Exchange 2007


Why use PowerShell instead of the Exchange Management Console?

Certain Exchange 2007 configuration settings are ONLY available through PowerShell cmdlets.  Therefore, why not take the attitude:  ‘I will pick-up the basics of PowerShell so when the day comes that I have no alternative, I will understand what to do’.

A more immediate reason for learning PowerShell in Exchange 2007 is that it’s often faster to type a few verb-noun combinations in the PowerShell box, than open the GUI and search through the menus.

PowerShell – The Way of the Future

PowerShell is the way of the future.  My old friend ‘Barking’ Eddie has only just given up with Edlin in favour of Notepad for editing text.  My point is don’t wait until 2020 to give up with DOS and transfer to PowerShell.  Incidentally, you can run internal commands like Ipconfig in PowerShell, just as you did in a DOS box.

I would like to amplify the statement that PowerShell is the way of the future by drawing attention to ways that you can use PowerShell to configure the operating system.  What I mean is that while Exchange 2007 is the killer reason to learn PowerShell, all knowledge gained from Exchange can be applied to configuring Windows Server 2008.

An Interesting Sub-plot

Exchange Management Console relays your GUI commands to Windows PowerShell, where the instructions are executed as if you typed the instructions at the command line.  Sooner or later it may cross your mind, ‘Hmm… I could take a short cut and just type the instruction directly into PowerShell’.

The Exchange Management SHELL is a snap-in, separate from the Management CONSOLE that also transfers GUI commands to PowerShell.  One benefit of the Management Shell is that can configure additional tasks such a configuring SMTP connectors, or disaster recovery of mailboxes. 

Guy Comes Full Circle

Having exhorted you to use PowerShell in Exchange 2007 at every opportunity, let us return to the GUI – Exchange Management Console.  I would like to plant the idea that comparing the menus with corresponding PowerShell commands helps you learn more about how the Exchange Server 2007 actually works.  My other reason is to give you ideas for further research, for example, the command: get-Help verb-Noun -full, will reveal more parameters, switches and properties.  Now you can often see those same properties listed in the GUI menus and dialog boxes.

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

The Final Breakthrough – Create Cmdlets

What may cement your conversion to PowerShell, is the realization that you can save PowerShell commands in text files, and then re-use them.  Two situations spring to mind, repetitive tasks, and monthly tasks where you have forgotten the carefully worked out commands that you configured those particular settings.  These text files are called cmdlets and have a .ps1 file extension. 

Creating cmdlets also reminds us that using short and simple PowerShell commands in Exchange 2007 only scratches the surface.  If you study PowerShell in any depth you soon appreciate that it has all the scripting techniques associated with a modern object based coding language.  As you take your PowerShell to the next level, lookout for its signature tune piping command (|), which means the output of the first clause | becomes the input of the second part of your script. 

Example of PowerShell in Exchange 2007

Problem Freddy has been sending huge attachments, and we want to curb this practice.  Here is a PowerShell command to configure Freddy’s mailbox.  Note the use of the pipe (|).

# PowerShell command to set the quota
Get-Mailbox "yourDom\yourFreddy" | set-Mailbox -ProhibitSendQuota 100MB

Installing PowerShell and .Net Framework

Think of PowerShell as a dormant ‘Feature’ of the operating system rather than a stand-alone program.  After all, PowerShell is a command-line equivalent the Exchange Management Console.  Instead of re-inventing the wheel, PowerShell taps into .Net’s library of objects.  Consequently, when you add PowerShell the wizard supervises the installation of .Net Framework and may prompt you for files, or suggest a visit to Microsoft’s website.

Another peculiarity of PowerShell is that installation steps vary with the operating system.  Windows Server 2008, Vista, Windows Server 2003 and XP all have idiosyncratic setup procedures.  What is happening is that Microsoft are moving towards a model where you Add PowerShell as ‘Feature’.  However, Windows Server 2003 and XP don’t have the ‘Add Feature’ mechanism, therefore you have to revert to a more primitive method of installing; for W2K3 and XP you need to download operating system specific files from Microsoft’s site.

Exchange Monitor from SolarWindsGuy Recommends: The SolarWinds Exchange Monitor

Here is a free tool to monitor your Exchange Server.  Download and install the utility, then inspect your mail queues, monitor the Exchange server’s memory, confirm there is enough disk space and check the CPU utilization.

This is the real deal – there is no catch.  SolarWinds provides this fully-functioning freebie, as part of their commitment to supporting the network management community.

Free Download of SolarWinds Exchange Monitor

Future challenges with PowerShell

There is another layer of complexity because of the relatively fast release of newer versions of .Net framework.  It seems to me that PowerShell 1.0 itself latches onto which ever version of .Net you provide.  Complications arise when other programs require an earlier version of .Net, and you upgrade to .Net Framework V3.5.

In the summer of 2008, PowerShell v 2.0 is close to release.  This will require at least version 2 of .Net Framework.  The killer reason to get v 2.0 is for remote scripting.

The golden rule, rely on the installation wizard.  If that fails, call for ‘Help install PowerShell’.

PowerShell Pre-requisites and Checklist

In the case of Windows 7 and later, you don’t need to download any extra files, just: ‘Add Feature’ –> Windows PowerShell.  However, for older operating systems, there are different versions of PowerShell for XP, Windows Server 2003 and Vista.  For such legacy systems only, you need to download PowerShell from Microsoft’s site.

Once you have installed PowerShell 2.0 or later, I recommend choosing the ISE (Integrated Scripting Engine) version, it will save buying a text editor.

General Example 1 – PowerShell Script to List All Event Logs

I have deliberately chosen examples that don’t rely on Exchange 2007

# Simple PowerShell script to list all the event logs.
Get-Eventlog -list

See more about PowerShell Eventlogs

General Example 2 – PowerShell Script to Find the Latest Errors

# PowerShell script to find Error messages in the System eventlog.
get-EventLog system -newest 50 | where {$_.entryType -match "Error"}

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of SolarWinds’ Network Performance Monitor

Example 3 – List Roles in Exchange Server 2007 with PowerShell

Unlike Examples 1 and 2, you to have Exchange Server 2007 installed before running these next PowerShell commands.

# PowerShell Exchange 2007 Server roles

Note 1:  When learning any PowerShell command, research more parameters with:
get-Help get-ExchangeServer

As a result you could append -status to the original command.

 Example 4 – Mailbox Statistics in Exchange 2007

# PowerShell script to retrieve Exchange 2007 mailbox statistics

Note 1:  When learning any PowerShell command, follow the experts, and try:
get-Help get-MailboxFolderStatistics -full

Note 2:  For safety I have only introduced the verb ‘get’.  For more action, but more risk, PowerShell has verbs such as ‘set’, ‘add’ and ‘remove’.  The other half of the cmdlet is the noun, or object, such as ‘Database’, ‘AddressList’, or ‘Queue’.

See more PowerShell Commands for Exchange

Summary of PowerShell in Exchange 2007

You don’t need an in-depth knowledge of PowerShell to manage your Exchange 2007 server.  Using PowerShell is often faster typing a few verb-noun combinations, than opening the GUI and searching through the menus.  Whether the underlying operating system is Windows Server 2003 or 2008, the wizard will supervise the installation of both PowerShell and .Net Framework.

If you like this page then please share it with your friends


See more Windows PowerShell tutorials

PShell Home   • Introduction   • Dreams   • 3 Key Commands   • PowerShell Help About   • Get-Help

PowerShell v 3.0   • Set-ExecutionPolicy   • Get-Command   • Cmdlet scripts   • Import-Module

PowerShell Version Check   • Backtick   • PowerShell examples   • PowerShell ISE   • Get-Member

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.