December 3, 2008

Quick Tip – Exchange 2007 setting OOF for users via Powershell…

As some of you might have guessed (from my last post) I have been working on an update to my web based Out of Office configuration tool, however, prior to me releasing the full application I would like to go through a very quick script that you can use straight away to set OOF messages for your users from your CAS server.

The main reason why I have published this so soon is because I came across an article recently that stated you cannot configure OOF using either VBSCRIPT or PowerShell – which is not entirely true.

Essentially there is no native scripting support of setting OOF in Exchange 2007, however through the work of Glen Scales there is a solution where you can use PowerShell (or indeed if you are writing custom applications languages such as C#) to set OOF.

Glen Scales is an Exchange MVP whom is renowned for his work in the field of scripting and programming for Exchange. Glen, rather helpfully put together a little Class Library entitled EWSOofUtil.dll (which he is in the process of expanding) which utilises the new “Exchange Web Services” API to allow for you to manipulate the OOF functionality of your users.

Before I continue I need to stress the following:

The EWSOofUtil.dll and its source code belongs to Glen Scales ** not me ** – Glen has released his code it into the public domain for general use, and I have asked permission to use the DLL both in my application and for example purposes, to which he has very kindly agreed. On a side note if you have not passed by Glen’s blog – please do so it is a fantastic resource for Exchange scripting.

However the example scripts that I have provided and will continue to provide are mine, which in the same way Glen are made available to you folks.

Down-loading EWSOofUtil.dll;

In order to make use of EWSOofUtil.dll to configure OOF responses for your users I recommend that you download it to the server that is holding your CAS (Client Access Server) role.

Therefore you should create a folder entitled \OOFScript\ on your CAS server – this folder can then be used to house the DLL and the scripts that this article will provide as examples.

When you have your folder structure created on your CAS – you can download the DLL from the following location:

zipEWSOofUtil.dll [92.3KB] – includes the source code

When the file has been brought down extract it into the folder that you have created – see below:


Preparing your CAS Server to Run Command Line PowerShell Scripts:

Open a PowerShell command Window and type in the following command:

set-ExecutionPolicy RemoteSigned and then press see below;


The set-Execution policy cmdlet essentially allows for you to configure how Powershell scripts (.PS1 files not cmdlets) are executed on your CAS Server.

There are four types of Execution policy:

  • Restricted – this will ensures that NO PS1 files can be executed
  • AllSigned – scripts that have been signed by a trusted publisher can be run on your machine
  • RemoteSigned – scripts that have been downloaded from the web can only be run if they have been signed by a trusted publisher
  • Unrestricted – Allow anything to run, regardless of the signed status

By assigning the “RemoteSigned” status to your execution policy, scripts that you have written directly on your server – or indeed downloaded from the Internet can be run from the command line (for example: PowerShell.exe \Demo.ps1. However it is important to note that IF you download the scripts from the Internet (for example any of the PowerShell scripts provided as part of this post (or indeed Blog)) you will need to perform the following actions in order for them to run from the command line:

  • Open the script using Notepad – evaluate the code and assure yourself that there is nothing within the script that is going to cause any damage, this is often best to do in a test lab.
  • When you have evaluated the safety of the script – Right click on the PS1 file and from the context menu that appears choose the “Properties” options which will display the following dialog box:



At the bottom of the File properties dialog you will see and entry entitled “Security” – click on the “Unblock” button and then click on the “Apply” button – this will then allow for the file to be run on the machine.

As mentioned, if you have set the Execution Policy to “RemoteSigned” and write the script directly on your server (or indeed a machine that is part of your domain) it should execute with no issues when passed as a parameter to “PowerShell.exe” – if however you download scripts from the Internet then you will need to evaluate then and unblock them using the above method prior to execution.

A Script to Set the OOF Status and Message for a Mailbox:

At this stage we should now be in a position to write a script that when run will set the OOF message for a given mailbox. The great thing about Glen’s DLL is that amongst other things it can run in the context of the logged on user account on the server – therefore if you are logged on as a Full Exchange Administrator you can execute the script and set the OOF without having to configure any specific permission within your Exchange environment (unlike previous CDO based scripts).

The following is a very simple PS1 file which can be used to set the OOF:

$PathToClass = "b:\oofScript\EWSOofUtil.dll" 


function setOOf($MB,$Message){ 

$oofutil = new-object EWSOofUtil.OofUtil 

$strMessage = $Message 


$persAddy = $Args[0] 

$persMess = $Args[1] 

setOOf $persAddy $persMess

The script is available for download here:

Simple Set OOF Script (set-OOf.ps1)

In order to run the the above script correctly you will need to change the $PathToClass variable to match the path on your CAS server where you downloaded Glen’s DLL to – so in my example I placed the DLL on “b:\oofScript\EWSOofUtil.dll

When you have modified the line above you are ready to drop to a Windows command prompt and run the script which using the following syntax:

PowerShell.exe \set-OOf.ps1 ‘OOf Message’

The following is an example of the correct syntax and the output from the script:


Essentially using the command above I have set both the Internal and External OOF message for the Administrators Mailbox to be “I am out of the Office” – please note that the comma is REQUIRED for the message on the command line.

If you now have a look at the OOF settings for the Administrators account in OWA you should see the following:


The above script is a VERY basic example of what can be accomplished using Glen’s DLL, you can for example use HTML code in the message, you can also take advantage of the scheduling features built into OOF in Exchange 2007. Many of these features will be present in the next release of the OOO admin tool.

If you would like to further explore the functionality of the EWSOofUtil.dll Glen has also provided some documentation here:

I hope that you find this useful.

Exchange 2007 Articles, Powershell 2 Replies to “Quick Tip – Exchange 2007 setting OOF for users via Powershell…”
Andy Grogan
Andy Grogan


2 thoughts on “Quick Tip – Exchange 2007 setting OOF for users via Powershell…

      Author’s gravatar

      Hi Andy,

      The link to the ps1-file seams to be broken.
      Request you to please provide a link to download the script.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.
%d bloggers like this: