Hello,
Thank you for the confirmation. Here is the updated script.
$phoneNumberPropertyName = "telephoneNumber" # TODO: modify me
$userParameterName = "param-Vertretung" # TODO: modify me
$oofStartDateParameterName = "param-abw-beginn" # TODO: modify me
$oofEndDateParameterName = "param-abw-ende" # TODO: modify me
$oofMessageTemplate = "I am on vacation until {0}
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 {1} {2} at {3} {4}." # TODO: modify me
# Bind to the source user
$userDN = $Context.GetParameterValue($userParameterName)
$user = $Context.BindToObjectByDN($userDN)
# Get source user first and last name
$firstName = $user.Get("givenName")
$lastName = $user.Get("sn")
# Get source user phone number
try
{
$phoneNumber = $user.Get($phoneNumberPropertyName)
}
catch
{
$phoneNumber = $NULL
}
# Get source user email
try
{
$email = $user.Get("mail")
}
catch
{
$email = $NULL
}
# 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 = $Context.Arguments.GetParameterValueAsIs($oofStartDateParameterName)
$automaticReplies.StartTime = $startTime
$endTime = $Context.Arguments.GetParameterValueAsIs($oofEndDateParameterName)
$automaticReplies.EndTime = $endTime
$endDate = $endTime.ToShortDateString()
$oofMessage = [System.String]::Format($oofMessageTemplate, @($endDate, $firstName, $lastName, $phoneNumber, $email))
# Internal message
$automaticReplies.InternalMessage = $oofMessage
# External message
$automaticReplies.ExternalAudience = "ADM_EXCHANGE_EXTERNALAUDIENCETYPE_ALL"
$automaticReplies.ExternalMessage = $oofMessage
$mailboxParams.AutoReplyConfiguration = $automaticReplies
# Save changes
$targetUser = $Context.BindToObjectByDNEx("%distinguishedName%", $True)
$targetUser.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")