Setting Auto-Replies for Shared Mailboxes with PowerShell

Tell External People that the Company’s on Holiday

The question arose about the best way to set auto-replies on shared mailboxes to inform external senders that the company is on holiday (public or otherwise). Some suggested using Flow for the job. I, of course, thought of PowerShell. I’m not against Flow: I simply think that PowerShell offers more control and flexibility, especially when multiple shared mailboxes are involved.

Auto-replies, or OOF (Out of Facility) notifications as they are known in the trade, go back to the dawn of email (before Exchange 4.0). It’s easy to set auto-replies with PowerShell using the Set-MailboxAutoReplyConfiguration cmdlet. The Get-MailboxAutoReplyConfiguration cmdlet reports the current auto-reply state of a mailbox.

A New Auto-Reply for Shared Mailboxes

The example solution uses a quick and dirty script to find all shared mailboxes in the tenant and set two auto-replies. One (brief) for internal correspondents; the other (less terse and nicer) for external people. Two variables are declared to set the start and end time for the scheduled auto-reply. If you specify a time, remember that Exchange Online runs on UTC so any time you set is in UTC. In other words, convert your local time to UTC when you set up the auto-reply. Rather bizarrely, Get-MailboxAutoReplyConfiguration converts the UTC time to local (workstation) time when it reports an auto-reply configuration.

#These times are in UTC
 $HolidayStart = "04-Aug-2019 17:00"
 $HolidayEnd = "6-Aug-2019 09:00"
 $InternalMessage = "Expect delays in answering messages to this mailbox due to the holiday between " + $HolidayStart + " and " + $HolidayEnd + ""
 $ExternalMessage = "Thank you for your email. Your communication is important to us, but please be aware that some delay will occur in answering messages to this mailbox due to the public holiday between " + $HolidayStart + " and " + $HolidayEnd + ""
 $Mbx = (Get-Mailbox -RecipientTypeDetails SharedMailbox | Select DisplayName, Alias, DistinguishedName)
    ForEach ($M in $Mbx) {
    # Set auto reply
    Write-Host "Setting auto-reply for shared mailbox:" $M.DisplayName
    Set-MailboxAutoReplyConfiguration -Identity $M.DistinguishedName -StartTime $HolidayStart -AutoReplyState "Scheduled" -EndTime $HolidayEnd -InternalMessage $InternalMessage –ExternalMessage  $ExternalMessage -ExternalAudience 'All' -CreateOOFEvent:$True }

Figure 1 shows the result when an external person sends email to a shared mailbox. You can be as creative as you like with the text.

An auto reply message created with PowerShell
Figure 1: An auto reply message created with PowerShell

Removing Auto-Replies

The scheduled auto-reply lapses when the end time arrives. If you want to remove auto-replies from all shared mailboxes, run the command:

<pre class="lang:ps">
# We assume that all shared mailboxes are in $Mbx
 ForEach ($M in $Mbx) {
   Set-MailboxAutoReplyConfiguration -Identity $M.DistinguishedName  -AutoReplyState "Disabled" }</pre>

For more information about working with shared mailboxes, see the chapter in the Office 365 for IT Pros eBook.

5 Replies to “Setting Auto-Replies for Shared Mailboxes with PowerShell”

  1. Hello, does it work with regular mailboxes without sharing option?. How can I configure a .txt file with a list of users I want to set the MailboxAutoReply. Something like this would work?

    $Mbx = (C:\mailboxList.txt Get-Content | Select DisplayName, Alias, DistinguishedName)
    ForEach ($M in $Mbx)

    If it is possible i just need to know how to build the txt file.

    1. I would use a CSV file (because you get named columns) and read the information in from it instead of a text file. After that, it’s just a matter of updating each mailbox with the autoreply information.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.