The script can be used with the If PowerShell script returns true condition to check whether an Exchange mailbox is configured to send automatic replies (Out-Of-Office messages). It returns True when a mailbox is configured to send automatic replies.
PowerShell
# Get mailbox parameters
$Context.ConditionIsMet = $False
try
{
$mailboxParams = $Context.TargetObject.GetMailParameters()
}
catch
{
return
}
# Check OOF configuration
$automaticReplies = $mailboxParams.AutoReplyConfiguration
$automaticRepliesStatus = $automaticReplies.AutoReplyState
switch ($automaticRepliesStatus)
{
"ADM_EXCHANGE_OOFSTATETYPE_DISABLED"
{
return
}
"ADM_EXCHANGE_OOFSTATETYPE_ENABLED"
{
$Context.ConditionIsMet = $True
}
"ADM_EXCHANGE_OOFSTATETYPE_SCHEDULED"
{
# OOF message is scheduled
# Check whether OOF is enabled right now
# Get current date
$currentDate = Get-Date
# Check OOF schedule
$startDate = $automaticReplies.StartTime
$endDate = $automaticReplies.EndTime
if (($startDate -lt $currentDate) -and ($endDate -gt $currentDate))
{
$Context.ConditionIsMet = $True
}
}
}