Setting Exchange Out of Office for multiple users with different messages

Out of Office rules in Exchange have been around a long time. They are a great way to let people within your organization know that you are on leave while also telling all your suppliers and external contacts the same thing. Out of Office messages can be initiated for various reasons. For example:

  • The email account will be removed on an upcoming date.
  • The person is out sick or on vacation.
  • The account has email forwarded to another account because the person has left the organization.
  • The company has merged and the email address will be updated with a new one.
Out of office exchange

One thing to remember: If a person sends you a message and gets the Out of Office response, subsequent messages from that person will not yield any responses. With Exchange 2016 and 2019, you can set Out of Office for users on the backend. You may be wondering why this would be necessary, as people have access to email on their phones and tablets and can usually set it themselves. But there may come a time when it needs to be done by the Exchange admin. Here are some examples:

  • The person is out ill, perhaps in the hospital, and cannot set their Out of Office.
  • The person had a death in the family.
  • The person was suspended or dismissed.
  • The company has decided to set Out of Office for all employees because they are shutting down.

There may be many other examples than the ones listed, but imagine you have to set Out of Office messages for 10,000 users in the company. Doing this manually takes hours or days (bad enough!), but it can also result in errors when things are not set correctly, or you miss one or two users’ OOF. This is where PowerShell comes to the rescue.

Exchange Out of Office and PowerShell: Perfect combination

Before you fire up PowerShell, create a CSV file with all the email addresses, followed by the Out of Office message. That message can be standard for all users or different for all users. I recently performed this task for a client that had over 10,000 mailboxes. The only thing that took long was the formatting of the CSV file to ensure the OOF message was in quotation marks and that the file was formatted correctly. After doing that and quickly putting together a script, I tested it in my lab, and all worked well. The next challenge was to push this out to over 10,000 users. What could go wrong if it worked in the lab?

Well, one thing that could go wrong could be that an account has its send and receive limits set to 0, and thus you cannot set the Out of Office for that user. It will give you an error message on screen, but you can deal with it quickly enough by simply increasing the limits to set the OOF.

Let’s move on to the PowerShell script so you understand what each section is doing:

$Users = Import-Csv C:\list.csv
foreach ($user in $users) {
Set-MailboxAutoreplyConfiguration -Identity $User.user -AutoReplyState Enabled -Internalmessage $User.msg -externalmessage $User.msg }

Line 1 of the code is importing the CSV file. If you had to run $Users from the PowerShell window, it should list the contents. If it doesn’t, then it has not read the file correctly or the location is incorrect.

Line 2 of the code creates a “for” statement as we are dealing with multiple users and information here.

Line 3 goes and sets the Out of Office message for each user based on what is captured in the CSV file. $User.user means it will look at the column called user and .$User.msg means it will look at the Msg column for each user and set it. Note: The AutoReplyState is enabled here, but you can change that to Scheduled with a date and time range as you need.

Because of the large number of users my client had, the script took about 40 minutes to complete. Depending on how large your organization is and the number of domain controllers, the information has to replicate, so be patient. If you do a check against a mailbox, you should start seeing the OOF set.

Creating your CSV file

Moving to the CSV file, here is a sample one below. You can update it or change the name as you need to.

Exchange out of office

As mentioned earlier, in the CSV, we have a User and Msg column separated by a comma, and we have the Out of Office message in quotation marks.

There is nothing special about this file — it was created in Notepad and saved as a CSV file in ASCII format.

I did a test using the <br> HTML code tag to separate the lines in the Out of Office message, but in the CSV file, the script ran but did not set anything. Once the <br> tag was removed, the Out of Office message was added to the Exchange account. It may be that it does not like the code in this example, but if you are doing one or two standard Out of Office messages straight from the Exchange Management Shell, the <br> tags work fine.

This small, easy script can save you hours of work instead of doing it manually. To turn the Out of Office messages off, you can simply use the code below. Null means set to nothing/default:

$Users = Import-Csv C:\list.csv
foreach ($user in $users) {
Set-MailboxAutoreplyConfiguration -Identity $User.user -AutoReplyState Disabled -Internalmessage $Null -externalmessage $Null }

Featured image: Shutterstock

About The Author

Leave a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top