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 <Path>\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:
EWSOofUtil.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 <enter>– 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 <path>\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"
[Reflection.Assembly]::LoadFile($PathToClass)
function setOOf($MB,$Message){
$oofutil = new-object EWSOofUtil.OofUtil
$strMessage = $Message
$oofutil.setoof($MB,"Enabled",$strMessage,$strMessage)
}
$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 <pathToScript>\set-OOf.ps1 <Primary SMTP Address of User> ‘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: http://msgdev.mvps.org/setoofexamples.htm
I hope that you find this useful.

[...] Quick (ish) Tip – Exchange 2007 – Setting OOF for Users via Powershell… [...]
By: Week(end) reading - subject: exchange on March 24, 2008
at 7:34 pm
[...] saw Andy posted this (http://telnetport25.wordpress.com/2008/03/16/quick-ish-tip-exchange-2007-setting-oof-for-users-via-p...) today and wanted to share my [...]
By: Carpe Diem: Flaphead.com @ Home : Exchange 2007 / Outlook 2003 / Blackberry & OoO on March 28, 2008
at 5:43 pm
We done something similar and the dll worked like a dream
http://blogs.flaphead.dns2go.com/archive/2008/03/28/exchange-2007-outlook-2003-blackberry-ooo.aspx
By: Flaphead on March 28, 2008
at 5:45 pm
I got an error as follows. Does anyone know how to resolve this.
GAC Version Location
— ——- ——–
False v2.0.50727 C:\oofScript\EWSOofUtil.dll
System.Net.WebException: The remote server returned an error: (401) Unauthorized
.
at System.Net.HttpWebRequest.GetResponse()
at EWSOofUtil.OofUtil.DiscoverOofURL(String caCASURL, String emEmailAddress,
String UserName, String Password, String Domain)
at EWSOofUtil.OofUtil.createesb(String EmailAddress, String UserName, String
Password, String Domain, String OofURL)
at EWSOofUtil.OofUtil.SetOof(String EmailAddress, String OofStatus, String In
ternalMessage, String ExternalMessage, DateTime DurationStartTime, DateTime Dura
tionEndTime, String InternalMessageLanguage, String ExternalMessageLanguage, Str
ing ExternalAudienceSetting, String UserName, String Password, String Domain, St
ring OofURL)
System.Net.WebException: The remote server returned an error: (401) Unauthorize
d.
at System.Net.HttpWebRequest.GetResponse()
at EWSOofUtil.OofUtil.DiscoverOofURL(String caCASURL, String emEmailAddress,
String UserName, String Password, String Domain)
at EWSOofUtil.OofUtil.createesb(String EmailAddress, String UserName, String
Password, String Domain, String OofURL)
at EWSOofUtil.OofUtil.SetOof(String EmailAddress, String OofStatus, String I
nternalMessage, String ExternalMessage, DateTime DurationStartTime, DateTime Du
rationEndTime, String InternalMessageLanguage, String ExternalMessageLanguage,
String ExternalAudienceSetting, String UserName, String Password, String Domain
, String OofURL)
By: Sujeeth on March 31, 2008
at 12:24 pm
Andy,
Very nice.
John
By: john weber on April 9, 2008
at 3:07 pm
Sujeeth, it looks like that you have run the script from a server that is not holding the CAS role – and /or the account you are using does have the correct permissions. If you have a look at Glen’s site he takes you through impersonation for the dll. – This may help.
By: Andy Grogan on April 9, 2008
at 7:41 pm
Sujeeth you seem to have the same issue as myself. The problem is that your internal certificate and autodiscover SCP don’t match. A simple workaround woudl be to specify the internal server name https://servername/EWS/exchange.asmx
Can anyone help me alter the script to do this? I have been trying but scripting syntax just eludes me.
Cheers
By: 1koncrawford on May 22, 2008
at 11:58 am
Through this DLL is it possible to use the script to export an OOF that is in place, delete the OOF and replace the new template contents with the original OOF message.
To address the BES issue, I’m finding I’m having to do that and its a PAIN. Just turning it on and OFF does not fix it. I spoke to RIM and they confirmed this.
By: Bobby on June 12, 2008
at 4:58 pm
Hello there,
i tried to make this work with the datetime scheduler.
but can not get a fix on how i get it on a specific time. like that i already schedule that im out of office fomr 01/01/2009 to 31/01/2009.
is this even possible ?
cheers
By: Jotte on November 26, 2008
at 9:16 am
Hi i am getting the “User is not the mailbox owner) when trying to use the dll:
———–
GAC Version Location
— ——- ——–
False v2.0.50727 C:\oofScript\EWSOofUtil.dll
System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapE
xception: Microsoft.Exchange.Data.Storage.AccessDeniedException: User is not mai
lbox owner. User = S-1-5-21-487931497-2597971174-555189064-1388, MailboxGuid = S
-1-5-21-487931497-2597971174-555189064-1229 —> Microsoft.Exchange.Data.Storage
.AccessDeniedException: User is not mailbox owner. User = S-1-5-21-487931497-259
7971174-555189064-1388, MailboxGuid = S-1-5-21-487931497-2597971174-555189064-12
29
at Microsoft.Exchange.Data.Storage.MailboxSession.Open(ExchangePrincipal mail
boxOwner, WindowsPrincipal authenticatedUser, CultureInfo cultureInfo, String cl
ientInfoString)
at Microsoft.Exchange.Services.ExchangeService.c__DisplayClass7.b__4()
— End of inner exception stack trace —
———-
What could be wrong ?
br,
Mart Meier
By: Mart Meier on January 26, 2009
at 2:18 pm
Hello
I have same problem and Jotte.
I want setup the date between 03/03/2009 to 10/03/2009.
Please Help me.
By: will on February 2, 2009
at 3:34 am
[...] [...]
By: EXCH - Autoresponder Exchange 2007 - MCSEboard.de MCSE Forum on February 12, 2009
at 9:40 am
Im getting this error. It did actually work a few times, but now appears to have stopped.
System.Net.WebException: The underlying connection was closed: The connection w
as closed unexpectedly.
at System.Net.HttpWebRequest.GetResponse()
at EWSOofUtil.OofUtil.DiscoverOofURL(String caCASURL, String emEmailAddress,
String UserName, String Password, String Domain)
at EWSOofUtil.OofUtil.createesb(String EmailAddress, String UserName, String
Password, String Domain, String OofURL)
at EWSOofUtil.OofUtil.SetOof(String EmailAddress, String OofStatus, String I
nternalMessage, String ExternalMessage, DateTime DurationStartTime, DateTime Du
rationEndTime, String InternalMessageLanguage, String ExternalMessageLanguage,
String ExternalAudienceSetting, String UserName, String Password, String Domain
, String OofURL)
By: Dan on March 4, 2009
at 12:17 am
Hi!
I use the dll an the oof script and it works very fine!
$oofutil.setoof($MBX, “Enabled”, $strMessageInt, $strMessageExt, $user, $pw, $domain, $casSrv).
But I dont’t know how to set the “ExternalAudienceSetting” to “ALL”
How do I have to call setoof?
Thanks!
By: Ed.D on April 9, 2009
at 1:11 pm
Hi Andy,
thanks a lot for this solution. Worked perfect for me!
I’ve used Glen’s dll to set internal/external message and configured ExternalAudienceSetting to ALL for my users as well!
Great!
Matthias
By: Matthias Hans on September 18, 2009
at 7:11 am
Hello,
the setoof works perfectly.
Is there a way to get the current oof message so that i can read it?
I tried getoof(“user@dom.de”,”enabled”) but it didn`t work.
By: Schuhmann on November 6, 2009
at 10:31 am