Along with the RC of Exchange 2010 this week the RC of the EWS Managed API made its debut. There are a number of changes some of which break a few of the scripts i've posted here there is full list of the changes on http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/7053c628-9227-4cd5-ba9d-ed6fe8d484cb. But the good thing is now OOF and Freebusy work and the DNS lookup for autodisover is another major improvement.
Setting the OOF is pretty easy with the API lets look at a few examples as before you first need to create a Service object and authenticate if you haven't used the EWS Managed API in Powershell before see this post as a primer. To use this OOF code you first need to download and install the RC version of the ManagedAPI from here.
So lets take it as read we have our $service object now to get the Offsettings its just one call with the email address of the Account you want to pull the settings for.
$oofSetting = $service.GetUserOofSettings("firstname.lastname@example.org")
A good point to remember when using any of the availability service Call like OOF and FreeBusy you need to always use delegate Access as EWS impersonation doesn't work with the availability service.
To show the OOF state just look at the State property
To show the oof message you have to look at the InternalReply or ExternalReply properties
To set the State and or the Message property you should first get the current setting modify the property you want to modify and then update the OOF.
eg to set the OOF of the currently logged on user you could use the following code.
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind
$oofSetting = $service.GetUserOofSettings($aceuser.mail.ToString())
$oofSetting.InternalReply = new-object Microsoft.Exchange.WebServices.Data.OofReply("Test 123")
$oofSetting.State = [Microsoft.Exchange.WebServices.Data.OofState]::Enabled