Microsoft PowerShell is a powerful task automation framework that consists of a command-line shell and associated scripting language. On its part, the Exchange Management Shell (EMS) is built on Windows PowerShell in order to manage Exchange Server objects. Within EMS, the savvy Exchange Admin is able to perform tasks ranging from the mundane creation of new email accounts to writing complex scripts. Indeed, the Exchange Management Console (EMC) is really a GUI that is built on top of EMS; there are actually many operations that can be performed only within EMS.

Let’s go through three tricks of using Exchange Server with PowerShell that you might have not been aware of:

 

1. Windows PowerShell Command Log

Windows PowerShell Command Log can be configured to log every Shell command that runs within EMC. This may be useful for novice admins in order to keep a log of the commands that they have performed. Even expert users operating within mission critical environments may want to enable it so as to facilitate the tracking of mistakes.

The log can be started by clicking on “View…” and selecting “View Windows PowerShell Command Log…” in EMC. Under the “Action” menu, click on “Start Command Logging” to enable logging. The PowerShell Command Log stays resident when logging commands and continues to do so until EMC is closed. It resumes logging when EMC is restarted. Anderson Patricio gives explains this further in his post on using Exchange 2010 Windows PowerShell Command Log.

 

2. Reviewing the Event Log

Events that pertain to Exchange can often be logged into the Windows Event Log. On a busy server that is used for many tasks however, it may be a hassle to filter out those related to Exchange on a regular basis. One simple and powerful way to leverage PowerShell would be to make use of the Get-Eventlog to export a CSV file of events that pertains to Exchange to regularly check for potential problems that may arise. Saving into CSV allows it to be easily imported and viewed by Microsoft Excel.

Get-Eventlog Application | while {$_.Source –ilike “Exchange*”} | Export-CSV [Path to output file]

 

3. Parsing Setup Logs for easy Review

Installing Exchange 2010 creates a folder named “C:\ExchangeSetupLogs” which contains numerous log files generated by the installation process. While a normal text editor will suffice to view the generated text files, Microsoft has provided the GetSetupLogs.ps1 script to process the log files. It will highlight warning and critical errors in different color so that an Exchange Administrator can quickly review it for installation errors. To use it, simply run: .\Get-SetupLog.ps1 from the Scripts folder.

 

Best Practices

Although this post was on using Exchange Server with Powershell, I would like to conclude with some of the best practices related to EMS that may be of help:

  • Make use of PowerShell scripting to automate repetitive tasks to save time and reduce mistakes.
  • Work on creating a cmdlet and script library that can be reused.
  • Develop a naming scheme that makes it easy to identify and intuitively understand the function of cmdlets in your library.
  • You can make use of EMS to create reports to identify email users with large mailboxes and user distribution reports, for example.
  • Create scripts to perform server administration tasks; use EMS to perform basic administrative tasks such as in the creation, moving and modification of mailboxes.

 

Like this post?

If you like this post and would like to receive more Exchange Server tips, as well as the latest Exchange Server posts from across the web, plus a free ebook with 42 Exchange tools, subscribe to the IT Dojo – Exchange Sensei series!