Automatic replies (OOF)

This code sample retrieves the following settings for Automatic Replies (OOF):

  • OOF status
  • Start time
  • End time
  • Message for senders inside my organization
  • Auto-reply to senders outside my organization
  • Message for senders outside my organization

In the below code sample, the $mailboxParams variable represents properties of an Exchange mailbox. To retrieve the properties, use the IAdmExchangeMailParametersOps::GetMailParameters method.

 How
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)

# Get Exchange properties
$mailboxParams = $user.GetMailParameters()
# The $mailboxParams variable represents properties of an Exchange mailbox

# Get 'Auto-Reply' configuration
$automaticReplies = $mailboxParams.AutoReplyConfiguration

# OOF status
$automaticRepliesStatus = $automaticReplies.AutoReplyState
Write-Host "Automatic Replies (OOF): " -NoNewline
switch ($automaticRepliesStatus)
{
    "ADM_EXCHANGE_OOFSTATETYPE_DISABLED" 
    {
        Write-Host "Disabled"
    }
    "ADM_EXCHANGE_OOFSTATETYPE_ENABLED" 
    {
        Write-Host "Enabled"
    }
    "ADM_EXCHANGE_OOFSTATETYPE_SCHEDULED" 
    {
        Write-Host "Scheduled"
    }
}

# Start time
Write-Host "`tStart time:" $automaticReplies.StartTime

# End time
Write-Host "`tEnd time:" $automaticReplies.EndTime

# Message for senders inside my organization
Write-Host "`tMessage for senders inside my organization:"
Write-Host $automaticReplies.InternalMessage

# Auto-reply to senders outside my organization
Write-Host "`tOutside My Organization message (Auto-reply to: " -NoNewline
$externalAudience = $automaticReplies.ExternalAudience
switch ($externalAudience)
{
    "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_NONE" 
    {
        Write-Host "Nobody):"
    }
    "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_KNOWN" 
    {
        Write-Host "Senders in my Contacts list):"
    }
    "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_ALL" 
    {
        Write-Host "All senders):"
    }
}

# Message for senders outside my organization
Write-Host $automaticReplies.ExternalMessage

See also