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.

Script repository

Check whether automatic replies are enabled

June 16, 2017 Views: 2939

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.

Edit Remove
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
        }
    }
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers