Posted by: Andy Grogan | July 25, 2007

VBSCRIPT to set Out of Office

I thought that I would take a break from KVS for a little while and blog about a neat little trick that I came across the other day.

Essentially my organisation has over 4000 mail users, which over periods of time a number of them can either go on long term sick, maternity leave, annual leave etc, and one of the most common things that they forget to do is set their Out of Office assistant.

My boss came over to me the other day and said “is there an easy way to configure the Out of Office without having to physically logon to the mailbox?”.

I thought about it, and then did a little research and came up with the following script: (Edit – found some problems – updated)

Set objMAPISession = CreateObject(“MAPI.Session”)

strExchangeSvr = InputBox(“Please provide the name of your Exchange Server”)
strMailbox = InputBox(“Please provide the name of the Mailbox that you wish to set OOO”)

strMAPI = strExchangeSvr & vbLf & strMailbox

On error Resume Next

objMAPISession.Logon “”, “”, False, True, 0, False, strMAPI

If err <> 0 Then
Wscript.Echo “An Error occured: ” & err.description
Err.clear
Wscript.Sleep 7000
Wscript.Quit
End If

strOOOMessage = InputBox(“Please type in the OOO message for this user”)

objMAPISession.OutOfOfficeText = strOOOMessage
objMAPISession.OutOfOffice = 1
strOOOMessage = objMAPISession.OutOfOfficeText

objMAPISession.Logoff
Set objMAPISession = Nothing

Essentially all you need to do is copy this script onto your Exchange server (although you need to ensure that the account that you are logged on with has rights to the mailboxes – permissions similar to EXMERGE are good) and then run the script.

You will be asked for the Exchange Server name, the Mailbox alias and the Out of Office message that you would like to set – voila!


Responses

  1. Great script! However, is there a way to add rules such as email forwarding? That way when I set OOO for a user I can then forward their emails to whoever will be covering for them?

  2. Nice, but if you exmerge level permissions, I’d just sign-in using OWA. Sorta defeats your bosses request though.

    Joshua, IMHO, I’d be more comfortable assigning delegate permissions to the user taking over. That way the end-user can turn them off at any-time.

  3. Hiya Eric, you comment is exactly what we used to do until I and my bosses got a little worried about having a number of admins being able to do this.

    My most recent version of the contains some additional features, and I new way of assigning permissions on a group basis (admittedly they are pretty much the same as before) but it is a little tidier.

    Thanks for you comments,

    Cheers

    A

  4. Great Script works great.. One thing though.. If you copy and paste directly into some script editor’s like
    Primal script the Quotes in the code do not come across correctly and creates an error when run.. easily corrected by replacing the (”) with (“).. other than that it’s a great script.. Also if you have the ESM installed on your Local Machine it will work from that machine too. Just works a little slower.. :-)

  5. Wish I’d seen this last year when I was trying to achieve the same thing. I came up with something a similar thing, although it runs as an internet explorer HTA and does the addition/removal of permissions in active directory.

    I’ll google your site first before I attempt any exchange work next time.

    Link to my script below should you be interested, but please remove it if posting links in comments is bad form.

    http://networknerd.wordpress.com/2008/10/07/hta-to-set-exchange-out-of-office-message/

  6. [...] she gets there. How’s your VB scripting? – Never tried this before, but looks OK to me. ——- http://telnetport25.wordpress.com/20…out-of-office/ My boss came over to me the other day and said "is there an easy way to configure the Out of [...]

  7. Does this runs for Exchange 2007 / Exchange 2007 Sp1 ? It is giving me error Line: 1 Char: 35 Error: Invalid character Code: 800A0408 Source: Microsoft VBScript compilation error

  8. Now after rectifying particularly look out for apostrophes and commas that do not display correctly. Now I am getting error Line: 1 Char: 35 Error:ActiveX component can’t create object:’MAPI.Session’ Code: 800A01AD

  9. Now after rectifying particularly lapostrophes and commas that do not display correctly. Now I am getting error Line: 1 Char: 35 Error:ActiveX component can’t create object:’MAPI.Session’ Code: 800A01AD


Leave a response

Your response:

Categories