Automatic replies (OOF)
The following code sample immediately enables Automatic Replies (OOF) for a mailbox.
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Enable OOF
$automaticReplies = $mailboxParams.AutoReplyConfiguration
$automaticReplies.AutoReplyState = "ADM_EXCHANGE_OOFSTATETYPE_ENABLED"
$endDate = ((Get-Date).AddDays(14)).ToShortDateString()
# Internal message
$automaticReplies.InternalMessage = "I am on vacation until $endDate
and will not see your message until then.
Your message sits safely in my Inbox awaiting my return.
If you need immediate assistance, please contact %adm-ManagerPhone%."
# External message
$automaticReplies.ExternalAudience = "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_ALL"
$automaticReplies.ExternalMessage = "I am on vacation until $endDate
and will not see your message until then.
Your message sits safely in my Inbox awaiting my return."
# Save the changes
$mailboxParams.AutoReplyConfiguration = $automaticReplies
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
The following code sample schedules enabling Automatic Replies (OOF) for a mailbox.
[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=example,DC=com"
$user = $service.OpenObject("Adaxes://$userDN", $null, $null, 0)
# Create an instance of the 'AdmExchangeMailboxParameters' class
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Schedule OOF
$automaticReplies = $mailboxParams.AutoReplyConfiguration
$automaticReplies.AutoReplyState = "ADM_EXCHANGE_OOFSTATETYPE_SCHEDULED"
$startTime = (Get-Date).AddDays(30)
$automaticReplies.StartTime = $startTime
$endTime = $startTime.AddDays(14)
$automaticReplies.EndTime = $endTime
# Internal message
$automaticReplies.InternalMessage = "I am on vacation until $endDate
and will not see your message until then.
Your message sits safely in my Inbox awaiting my return.
If you need immediate assistance, please contact %mobile%."
# External message
$automaticReplies.ExternalAudience = "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_ALL"
$automaticReplies.ExternalMessage = "I am on vacation until $endDate
and will not see your message until then.
Your message sits safely in my Inbox awaiting my return."
$mailboxParams.AutoReplyConfiguration = $automaticReplies
# Save changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
See also
- Performing Exchange tasks
- Writing ADSI scripts
- Server-side scripting
- IAdmExchangeMailParametersOps
- IAdmExchangeMailParameters
- IAdmExchangeMailboxParameters
- IAdmExchangeMailboxAutoReplyConfiguration
- Online script repository