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.

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

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*) 

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

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.

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

 


See More Windows PowerShell Examples of Real-life Tasks

PowerShell Tutorials  • PowerShell Examples  • IpConfig  • Get-Counter  • PowerShell NetSh

Monitor Performance – PowerShell  • PowerShell temp   • PowerShell Delete Temporary files

PowerShell WOL (Wake-on-Lan)  • Services   • Change Computer Description Registry

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.