Out Of Office Multiline Message through PowerShell

Out Of Office Multiline Messgae

We receive requests to activate Out Of Office messages for several mailboxes on a daily base. It is not a complicated task but can be time-consuming when you need to set up Out Of Office messages containing multiple lines, that you adjust within HTML tags, for a variety of mailboxes from several customers. You probably know what I mean: Are the line break tags at the right place? Does the next paragraph begin where it should?

For this reason, I wanted to achieve that we are able just to copy and paste the Out Of Office message from the request, provide the type of the AutoReplyState (enable, disable, schedule) and get visual feedback on the applied attributes, without the need to picture the original customer OOO message in HTML. My script at point 3 of this post will exactly do this.

In the following lines, you can find options on how to activate or disable Out Of Office messages from PowerShell.

1 -Set up a one-liner absence message using PowerShell:

If you just want to give a short note of your absence the command below should be sufficient:

Get-Mailbox -Identity MailboxToSetupOOO | Set-MailboxAutoReplyConfiguration -AutoReplyState Enabled -InternalMessage “EnterYourInternalMessageHere” -ExternalMessage “EnterYourExternalMessageHere”

Change the AutoReplyState according to your needs:

Enabled = Activation is valid from the point you hit Enter without a defined End-Time
Disabled = Deactivates the Out Of Office message. It does not matter if you have defined an Internal or External Message.
Scheduled = Define a Start-Time and End-Time during which Out Of Office messages are sent.

If you set the AutoReplyState to Scheduled you will need to provide a Start-Time and End-Time. Enter the date-format according to your system settings followed by start and end time:

Get-Mailbox -Identity MailboxToSetupOOO | Set-MailboxAutoReplyConfiguration -AutoReplyState Scheduled -InternalMessage “EnterYourInternalMessageHere” -ExternalMessage “EnterYourExternalMessageHere” -StartTime “DateAccordingYourSystemDateFormatFollowedBy 00:01:00” -Endtime “DateAccordingYourSystemDateFormatFollowedBy 23:59:00”

2 -Set up a multiline absence message using HTML tags in PowerShell:

To set up a multiline Out Of Office message you will need to use HTML tags to preserve the layout.
For example, you receive a request to activate the following message:

Dear Sender,

Thank you for your email.

I am currently out of the office with no access to my emails.

Please note that your mail will be read with delay.

Kind Regards

One option can be to use <br> tags at the end of each line and place an additional <br> tag for an empty line in your InternalMessage / External Message.

“Dear Sender,<br>
<br>
Thank you for your email.<br>
<br>
I am currently out of the office with no access to my mails.<br>
<br>
Please note that your mails will be read with delay.<br>
<br>
Kind Regards<br>

This option suits mostly scenarios where the message layout does not change and you only want to edit the content. The <br> tags stay where they are.

The next possibility is a little bit more convenient. Instead of using <br> tags you could use <pre></pre> tags and simply paste the Out Of Office message between them:

<pre>Dear Sender,

Thank you for your email.

I am currently out of the office with no access to my emails.

Please note that your mail will be read with delay.

Kind Regards</pre>

This is also how the script at point 3 works. It utilizes the <pre></pre> tags.

3 -Script to activate a multiline Out Of Office message:

Usage:

– Enter the email address of the mailbox where you want to activate an Out Of Office message.
– Paste the Out Of Office message. Please ignore possible color differences after pasting the message.
– Choose the appropriate AutoReplyState.
– When the script has finished it gives visual feedback. Verify that the applied values are correct.

 

Sorry if the common PowerShell colors are displayed here in a different way. It is no easy task to find a plugin that renders and exactly highlights PowerShell in the Backend. ( no hosting on 3rd party servers )
I thought about rewriting the CSS for this one, but it would be too time-consuming. So if you know a plugin or method to highlight PowerShell code that preserves the PowerShell color scheme I would be grateful to get a hint.

#———————————————————————
# Activate OOO Messages
# Written by WebBanshee
# Feel free to use
#———————————————————————

# clear screen #
cls

# set formatlist output to the given value
$FormatEnumerationLimit = $null

# Mailboxname to set OOO message #
[string] $mbname = Read-Host -prompt ‘Enter Mailbox to set OOO’

while ($mbname -notlike “*@*” -or $mbname -notlike “*.*”){

write-host -ForegroundColor yellow “Please provide a valid smtp address!”

[string] $mbname = Read-Host -prompt ‘Enter Mailbox to set OOO’

}

# OOO message #
Write-Host “”

[string] $message = Read-Host -Prompt ‘Paste OOO Message here – Leave blank if you plan to disable’

# Place OOO message inside HTML Tags to preserve formatting #
$oootxt = ‘<pre>’ + $message + ‘</pre>’

# Actions #
Write-Host “”

[string] $mode = Read-Host -Prompt ‘(e)nable (d)isable or (s)chedule’

# (e)nable #
if ($mode -match “e”) {

get-mailbox -Identity $mbname | Set-MailboxAutoReplyConfiguration -AutoReplyState Enabled -InternalMessage $oootxt -ExternalMessage $oootxt

}

# (d)isable
if ($mode -match “d”) {

get-mailbox -Identity $mbname | Set-MailboxAutoReplyConfiguration -AutoReplyState Disabled

}

# (s)schedule
if ($mode -match “s”) {

[string]$startdate = Read-Host -Prompt ‘Enter Start-Date according to your system time. For example: mm/dd/yyyy – Start-Time will be valid from 00:01’

[string]$starttime = “$startdate 00:01:00” # You can change the StartTime here

[string]$enddate = Read-Host -Prompt ‘Enter End-Date according to your system time. For example: mm/dd/yyyy – End-Time will be valid until 23:59’

[string]$endtime = “$enddate 23:59:00” # You can change the EndTime here

get-mailbox -Identity $mbname | Set-MailboxAutoReplyConfiguration -AutoReplyState Scheduled -InternalMessage $oootxt -ExternalMessage $oootxt -StartTime $starttime -EndTime $endtime

}

# Display Results
Write-host “————————————————————————–”

Write-host -ForegroundColor green “The following OOO settings have been applied to mailbox:” $mbname

$a = get-mailbox -Identity $mbname | Get-MailboxAutoReplyConfiguration | select AutoReplyState, StartTime , Endtime, InternalMessage, ExternalMessage | fl

$a

Annoyed by waiting for Outlook to start?
Maybe you can sort it out with this one:

Slow loading Outlook profile

7 thoughts on “Out Of Office Multiline Message through PowerShell”

  1. After the option to set a OoO message in ECP disappeared in our environment, I was only able to set a one-liner OoO message with PowerShell, which is very ugly. The is exactly what I was looking for. I also proof-read and tested your script. Still works like a charm in 2021. Thank you very much for this detailed article!

  2. Hi, unfortunately the tags does not work for me.. it get only the first line of the message but not the others lines.. im forced to use the … any ideas? Many thanks!!!

  3. Hi, Unfortunately I am the same. I pasted the message which contains 18 lines in total and a few blank lines in between. However i cant get it to work with even 2 lines. Any tips? Thanks

    1. Hi,

      I have tested it in two Exchange 2019 CU9 environments. It worked by splitting the lines with the br tags, it worked by using the pre tags and pasting the lines between them and it worked with the script as well.
      The tags and the message should be placed within quotation marks. Without knowing how you exactly do it there is not much I can help you with.

      Sam

  4. will look into rewriting the script a little i need interal a other message then external.
    so i need the option to do this twice or i need to change the script and run it twice.

Leave a Reply

Your email address will not be published. Required fields are marked *