I don’t like Mondays (tell me why), I don’t like Mondaaays–get your Out of Office set automatically if you don’t work on a specific day…

As the Boom Town Rats (and Sir Bob) said, I don’t like Mondays. Some of you lucky folks don’t have to work on a Monday (or indeed some other days of the week) – so are you tired of setting your Out of Office the night before you are not in the office on a regular basis?

Well the other day I posted an article that was based around some fun that you can have with the “Set-MailboxAutoReplyConfiguration” within Exchange 2010. Naturally I posted the article on Twitter and a chap called Peter De Rop came back and asked could the script be used to activate an OOF every Monday as he is not in the office.

I thought that this was a great idea – I started thinking – could I develop a Powershell script which could be scheduled to automatically set the Out of Office for people whom do not work on specific days of the week, and then turn it off on the days which they do work?

So the following is what I came up with:

# Set a users Out of Office Automatically based upon their working pattern
# Exchange 2010 only!
# Version 1.0
# Author: Andy Grogan
# http://www.telnetport25.com

$Day = Get-Date
$TodayDate = $Day.DayOfWeek
$Interim = Get-Mailbox | Select Identity,CustomAttribute15 | where {$_.CustomAttribute15 -ne ""}
[array]$CustomAttrib = $Interim.CustomAttribute15.Split(";")

Foreach($attrib in $CustomAttrib){
    
    if($attrib -eq $TodayDate){
        Set-MailboxAutoReplyConfiguration -Id $Interim.Identity -AutoReplyState Enabled -InternalMessage "Sorry I am out of the office I don't work on: $TodayDate" -ExternalMessage "Sorry I am out of the office I don't work on: $TodayDate"
    }else{
        Set-MailboxAutoReplyConfiguration -Id $Interim.Identity -AutoReplyState Disabled
    }
}

The script works by looking at “CustomAttribute15” of all the users within your organisation and parses the name of the day of the week which they do not work on if the value is populated correctly.

For example; if you have a test account (or normal account) who does not work on Monday,Wednesday,Friday that you would like to set a generic Out of Office for on those days – you can within the Exchange 2010 Management Console can add the names of the days (separated with a “;”) to “CustomAttribute15” – see below

oofFunimgs005

The script above can then be scheduled from the Windows Task manager (probably from within a Batch file that calls Powershell and the script as a parameter) at midnight each night – and when it runs will set the Out of Office for all relevant users.

There are naturally some changes that could be made to improve the script – but it is provided to get your creative juices going – hope that you have fun!

Sharing is caring!:

2 thoughts to “I don’t like Mondays (tell me why), I don’t like Mondaaays–get your Out of Office set automatically if you don’t work on a specific day…”

  1. I have not been able to get this to work. I get this error message when I run it:
    You cannot call a method on a null-valued expression.
    At C:\scripts\oofAutoReplyDaily.ps1:10 char:56
    + [array]$CustomAttrib = $Interim.CustomAttribute14.Split <<<< (";")
    + CategoryInfo : InvalidOperation: (Split:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo : InvalidData: (:) [Set-MailboxAutoReplyConfiguration], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-MailboxAutoReplyConfiguration

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.