PowerShell Ezine, Logon Scripts

Ezine 165 - PowerShell Commands for Exchange 2007

Ezine 165 - PowerShell Commands for Exchange 2007

The purpose of this ezine is to give you another reason to learn PowerShell.  In particular, I want to show you how easy it is to use PowerShell commands in Exchange 2007.

Topics for PowerShell in Exchange 2007

This Week's Mission

My mission is to alert you to the important role played by PowerShell within Exchange Server 2007.  The benefit of learning these PowerShell commands is to save time.  I want to convince you that it's quicker to type a one line cmdlet, than drilling down through 3 menus levels in a GUI to find the equivalent setting.  Another benefit is that adjusting some obscure Exchange configurations is ONLY possible by using PowerShell in the Exchange Management Shell; there are some settings which are just not available in the GUI.

Furthermore, techniques that you learn for Exchange 2007 will help with Windows Server 2008.  I believe that there is a place for PowerShell commands to replace some long-winded GUI configuration.   Moreover, PowerShell really is the way of the future and is so much better than the old dos shell.

To get started with your quest, take advantage of the time-honoured method of cheating; copy the most appropriate example that Microsoft provide and then paste that PowerShell code into your Exchange Management Shell.  If necessary, alter a few values to suit your Exchange Server 2007.  A more sophisticated spin on this copy and paste approach is to become a researcher and trawl Exchange 2007's help for suitable PowerShell examples.  Then take the extra step, dissect, understand, and modify Microsoft's example code to suit your circumstances.

This Week's Secret

What is it that UNIX techies love most about their operating system?  The answer is to be found in the muscle and efficiency of their command line shells, such as the 'bash', or the KORN shell (ksh).  Now with PowerShell, you can feel the same instant control over your Exchange Server 2007.  One reason the band of PowerShell aficionados is growing so fast is because PowerShell is a very easy language to master the basics. 

We humans are inherently lazy animals, and we are only going to do something one way, as opposed to another way, if that way is faster.  The problem with typing in PowerShell rather than clicking in GUIs such as the Exchange Management Console is this; you have to invest time learning the spelling of PowerShell commands, before you become faster than configuring the same settings by clicking on menus in the GUI.  But trust me, like the UNIX techies, you will come to love the power of this Exchange shell.

Exchange 2007 - PowerShell Commands

If you have dabbled with a few of my PowerShell scripts, then my suggestion to investigate Exchange 2007 is a natural learning progression.  Even if you are a complete beginner, it's not difficult to find Exchange 2007 examples, then copy and paste the code into PowerShell. 

Pre-requisite

To actually run these scripts you need an Exchange 2007 server.  This is because you don't get the additional Exchange cmdlets unless you install Exchange 2007.  However, if you are a PowerShell enthusiast, but don't have such an Exchange server, it's still worth skimming this information to file away for future use.

The good news is all the Exchange 2007 PowerShell commands are short; most instructions have only one line.  For example:
get-Mailbox –identity "Guy Thomas"

Furthermore, the Exchange commands follow the traditional PowerShell verb-Noun pairing (get-Mailbox), followed by a parameter (-identity). 

The only bad news is that some of the nouns have long-and-strange names.  For instance:
Set-owavirtualdirectory -identity "owa (default web site)" -LogonFormat FullDomain. 

This example is typical of Exchange 2007's specialist nouns; OwaVirtualDirectory is the place where you set the forms-based logon to show the full domain (CP\Guyt) style of logon.

ˆ

More Examples of Exchange 2007 Cmdlets

Microsoft provides over 100 cmdlets for Exchange 2007, here are a handful of examples so that you get the idea of what might be possible with PowerShell on a mail server.

LogonStatistics
get-LogonStatistics -Database YourDatabase | fl
or
get-LogonStatistics -Server Bigserver

Note:  Check the importance of the parameters -Database or -Server, and thus adjust these examples to filter 'Logon Statistics' in your Exchange Organization.

Create a Distribution Group
New-DistributionGroup -Name "Cynics" -OrganizationalUnit "Cp.com/Managers" -SAMAccountName "Cynics" -Type "Distribution"

Note:  A rare use of the verb 'New'.  Observe the required information, for example '-name' and '-type'.

Three verbs to control an Exchange service, 'Suspend, Resume, or Enable'
The DatabaseCopy noun, or object, combines with these three verbs:
suspend-DatabaseCopy
resume-DatabaseCopy
enable-DatabaseCopy

Note 1:  Here are simple, but effective cmdlets to gain control of a service from the command line.  After a few attempts, typing one of these three examples would be quicker than drilling down to the same setting in a GUI.

Note 2:  If you master this technique for DatabaseCopy, then you can modify this command to control other Exchange objects such as Mailbox, StorageGroupCopy, or UMServer. (Unified Messaging Server)

Remember Your Three Trusty Techniques - Seek PowerShell's Help

In the last month I have seen a few sportsmen perform badly under pressure, their technique seems to desert them when they compete at a higher level than normal.  So it is with intermediate PowerShell scripters, when faced with the strange new Exchange nouns they forget the basics.  Therefore, if you do get stuck remember your technique and call for one of these three trusty help methods:
1) get-help verb-Noun
   E.g. get-help verb-VeryLongAndTrickyExchangeName (also remember to append the -full switch)
2) verb-Noun | get-member (remember that | pipe) 
3) To see which commands are available try: get-command a*  (or set*, new*, even enable*) 


If you are looking for handy network utilities, try some of the free downloads at Tools4Ever


Summary of PowerShell's for Exchange 2007

Configuring Exchange 2007 is a killer reason to learn PowerShell.  Moreover, Windows techies are seeing the pendulum swing away from using the GUI to manage their servers; inertia is moving towards the UNIX style of using a command-line shell - enter PowerShell with its 100 or more cmdlets.

See more Windows PowerShell real life tasks

PowerShell Home  • Real life tasks  • IpConfig  • Exchange  • Services  • Syntax

Com objects  • PowerShell Registry

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

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

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

Please report a broken link, or an error.