Script repository

Check whether automatic replies (OOF messages) are enabled

Updated on: Jan 18, 2026, Views: 3962

Exchange

The script checks whether the automatic replies (OOF messages) feature is enabled. To execute the script, use the If PowerShell script returns true condition in a business rule, custom command or scheduled task configured for the required object type. The script returns $true if the automatic replies (OOF messages) feature is enabled.

# 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
        $currentDate = Get-Date
        
        # Check OOF schedule
        $startDate = $automaticReplies.StartTime
        $endDate = $automaticReplies.EndTime

        if (($startDate -lt $currentDate) -and ($endDate -gt $currentDate))
        {
            $Context.ConditionIsMet = $True
        }
    }
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.