How To Set Out Of Office Automatic Replies With Powershell

I’ll never forget the day our Operations Manager sent out an email to the entire company, an hour before we were leaving for a holiday, giving everyone the message we were to set for our Out Of Office automatic reply in Outlook. And, the end of the message said, “and Dave will set all of the shared mailboxes”.

Uhhhh… come again?

Our company employs a LOT of shared mailboxes. I don’t like setting my own Out Of Office, let alone doing it for 20+ mailboxes that aren’t mine.

IT professionals need a couple of traits that make us great engineers; we have a lazy side, and repetitive, monotonous tasks drive us crazy. This drives us to invent ways to do those boring, repetitive tasks for us.

This calls for a script!

$Start = "11/26/2025 14:00:00"
$End = "12/01/2025 08:00:00"
$Message = "<p>Thank you for your email. The Bradbury Maiden Company is closed for the Thanksgiving Holiday. We will return Monday morning.</P><p>Have a Happy Holiday!</p>"

Connect-ExchangeOnline

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox | Set-MailboxAutoReplyConfiguration -AutoReplyState Scheduled -StartTime $Start -EndTime $End -InternalMessage $Message -ExternalAudience All -ExternalMessage $Message

This script returns a list of all shared mailboxes in your Exchange organization and sets the AutoReplyConfiguration using the values you provided. It sets both the Internal and External messages to the same thing. It takes under a minute to update 30 shared mailboxes. Way better than doing it manually!

Things to keep in mind

First, you need to have the Exchange Online Powershell Module installed. Second, time must be specified in 24-hour format. And, third, the Message properties can use HTML. This is how you achieve formatting in the body of your email.

Possible Tweakes

Set everyone’s mail box

If you remove the -RecipientTypeDetails SharedMailbox parameter, it will return all mailboxes on the system.

Different Internal and External Messages

The -InternalMessage and -ExternalMessage parameters control which messages are sent to you based on who you are replying to. You may want to send a different message to people inside your organization than those outside of your organization.

An easy way to do this would be to rename the $Message variable at the top to $InternalMessage, make a new variable called $ExternalMessage, define the messages, and add them to the proper parameters.

Exclude Mailboxes

I’m sure there is a more elegant way to do this, but here’s how I set all the mailboxes except for a few (maybe they shouldn’t send a message).

First, define the list of mailboxes to excludeusing a list. In PowerShell, you start a list with ‘@” followed by a comma-separated list inside of parentheses.

$Exclude = @('[email protected]','[email protected]')

Then, add this block to the end of the script

Foreach ($email in $Exclude) {
Set-MailboxAutoReplyConfiguration -Identity $email -AutoReplyState Disabled
}

This block turns Automatic Replies off for each person in the $Exclude list. So, first, all Automatic Replies are turned on, and then we go back through to turn off a select few.

Happy scripting!

Leave a Comment