Computer Performance, Exchange 2007

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.

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

Guy Recommends: SolarWinds Engineer's Toolset v10Engineer's Toolset v10

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and the tools teaches me more about how the system literally operates.

There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.  Download your copy of the Engineer's Toolset v 10

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.

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'.

Instructions for Running PowerShell CodePowerShell on Exchange Server 2007

Here are step-by-step instructions to execute simple PowerShell commands.

Method 1 (Quick)

  • Launch PowerShell
  • Copy the code into memory
    (For instance, from Example 1 below)
  • Right-click on the PowerShell symbolPowerShell Scripts
  • Edit --> Paste
  • Press enter to execute the code
  • See screenshot to the right

 

Method 2 (Best Long Term)

  • Prepare to run cmdlets with this PowerShell command:
    set-ExecutionPolicy RemoteSigned
  • Copy the code below into a text file.
  • Save the file with a .ps1 extension, for example: Eventlog.ps1
  • In PowerShell, navigate to where you saved Eventlog.ps1
  • Issue this command:
    .\network 
    (dot backslash filename)

 

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

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: SolarWinds LANSurveyorSolarwinds LANSurveyor

LANSurveyor will produce a neat diagram of your network topology.  But that's just the start; LANSurveyor can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you take a free trial of LANSurveyor then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download a Free Trial of LANSurveyor

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
get-ExchangeServer

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
get-MailboxFolderStatistics

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'.

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.

See more Microsoft PowerShell tutorials

PowerShell Home  • Introduction  • Dreams  • 3 Key Commands  • Cmdlet scripts  • Real life tasks

Remote PowerShell  • -Online  • WinRm and WSMan  • Invoke-Command  • Jobs  -asJob   • PowerShell

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This Website

GFi Events Manager

Guy Recommends: GFi EventsManager

Let GFI EventsManager do the dirty work! Have event logs monitored automatically and get warned about critical events! Download a copy here

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.