Wednesday, February 25, 2015

Starting Exchange Management Shell in Windows PowerShell

In our previous blog posts (e.g. How to check the number of autoreply emails sent from Exchange) we described various tools and methods utilizing Exchange Management Shell. Since EMS is nothing more than a normal PowerShell console, just with special Exchange module loaded it should be possible to run these Exchange cmdlets (e.g. get-transportagent) directly in the Windows PowerShell, without looking for the EMS shortcut. This is also helpful when you mistakenly launch Windows PowerShell console with the Exchange cmdlet in mind only to discover that it does not work.

Below you'll find two alternative methods of running Exchange PowerShell instead of using the Start menu shortcut. Please note that these solutions work only when you're logged on directly on the Exchange Server.

1. Execute a special script from the EMS shortcut directly in the PS console.

If you right click the EMS shortcut and open its properties you'll notice that it contains specific PS script file as a parameter:

A full name of this script parameter is as follows:

. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'

Therefore, it is a matter of running it in the standard PowerShell window. Make sure that you launched the PS console with the administrative privileges. Additionally if you want to run it on Exchange 2013 make sure to replace the "V14" part of the script path to "V15".

As the resulting screen suggests - the Exchange Powershell cmdlets are successfully imported. However, there is one last step to perform. Run the following command to complete the EMS launching process:

Connect-ExchangeServer -auto

You are now ready to run typical Exchange cmdlets.

2. Add the Exchange snapin in the PS console.

This method is fairly easy as it requires running only one command in the normal PowerShell console:
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

After the snapin loads, you are ready to run cmdlets. Unfortunately, this method does not support all available Exchange commands.

There is also another way of running Exchange Management Shell in the standard Windows Powershell console via Powershell Remoting. With this method, you can run scripts on your server even from the remote workstation without the need to launch it directly on the Exchange machine.

We'll cover PowerShell Remoting to the Exchange server in the next blogpost - stay tuned!

You can also read:

Thursday, February 12, 2015

How to check out of office status in Exchange

If you need to check an automatic Out-Of-Office (OOF) reply status for the given mailbox and you do not want to launch Outlook, or simply do not have it installed on the server, there is a quick way to do so. Run the following script in the PowerShell console:

Get-MailboxAutoReplyConfiguration "username"

Replace the "username" phrase with the actual user mailbox name to get the result. 

Among other properties, such as the body of the automatic message or activity timeframes, the command returns also the information, whether the automatic reply is enabled or disabled. You can see it in the line titled AutoReplyState.

To get the automatic reply status for all mailboxes in your organization you can use the following command:

Get-Mailbox | Get-MailboxAutoReplyConfiguration

The Get-Mailbox command gathers a list of all mailboxes from your server. The result is then transferred (piped) with the "|" symbol to the Get-MailboxAutoReplyConfiguration.

To filter and show only these users, that actually have the Out-Of-Office enabled, run the following cmdlet:

Get-Mailbox | Get-MailboxAutoReplyConfiguration | Where-Object { $_.AutoReplyState –eq “scheduled” }

As you can see in the above example, another level of data "piping" is applied. The list of all mailboxes is "piped" to the Get-MailboxAutoReplyConfiguration, which is then transferred to the filtering command, that shows only mailboxes with the OOF status "scheduled"

You can also easily disable the OOF message for the selected mailbox:

Set-MailboxAutoReplyConfiguration -Identity "username" -AutoReplyState Disabled

If the PowerShell scripting is not comfortable enough for your daily use, or you simply prefer a graphical user interface to manage automatic replies, you can use a third-party tool, such as MSH Exchange Autoresponder. With it you can easily and centrally manage not only OOF messages, but also first contact autoreplies, order reception confirmations, set up keyword triggering conditions, schedule activity timeframes and more.

Monday, February 2, 2015

How to check the number of autoreply emails sent from Exchange

In the following guide, we'll show you how to quickly check the number of autoresponder emails sent from your server with a single PowerShell cmdlet.

These statistics might be used to check, whether your office's working hours cover your customer's activity, the amount of traffic that is reaching your absent users and more.

Also with this script you can check how many times the MSH Exchange Autoresponder was triggered.

Start your Exchange Management Console first. Enter the following command in it:

Get-MessageTrackingLog -Start "02/02/2015 18:00:00" -End "03/02/2015 06:00:00" -Subject "Autoreply" -Eventid Send | Measure-Object 

The result is the number of emails, that were sent between 6:00PM 02/Feb/2015 and 6:00AM 03/Feb/2015, and contained the word "Autoreply" in their subject.

Simply replace values of the following parameters to get your own stats:

  • Start - the beginning of the date/time range, where the script looks for matching emails
  • End - the end of the date/time range 
  • Subject - the phrase that the script looks for in the subject field of analyzed messages. For autoreplies it is often the "automatic response" phrase or "Autoreply"
  • Eventid - the state of the message, whether it was sent (Send) from your server, received (Receive) etc. 

The result of the Get-MessageTrackingLog command is additionally "piped", redirected (with the "|" symbol) to the Measure-Object command, which simply counts all the matching messages. Without that command, you would receive a full list of all emails meeting the search criteria.