Automatically set out of office replies for all users (Microsoft 365)

Share This

As the festive season approaches, schools and businesses alike often close or operate with reduced staffing. Setting out-of-office replies during this period is a simple yet effective way to manage expectations, maintain professional communication, and ensure compliance with GDPR requirements, particularly regarding Subject Access Requests (SARs).

By informing senders of office closures, organisations can reduce frustration, protect staff wellbeing, and avoid potential legal risks. Common practice amongst most schools and organisations is to list their holiday dates and provide a pre-determined response along with dedicated DPO (Data Protection Office) email should any SARs come in while staff are enjoying well earned down time.

You can instruct staff on how, what and when to set an out of office reply, but you can guarantee at least one or two staff will fail to do so before you break up for the holidays. To combat this I will show you how you can automatically set Out Of Office (Automatic Replies) to all users in your organisation using Microsoft 365 and Powershell.


1. Prepare Your CSV File

Create a CSV file Emails.csv with just one column containing all your users email addresses (You can export from AD or SIMS)

UserPrincipalName
user1@yourdomain.com
user2@yourdomain.com
user3@yourdomain.com

Save your CSV file somewhere easily accessible.

2. Import/Install Exchange Online Module

You now need to  install and/or import the EOL Module

Install-Module -Name ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement

3. Connect to Exchange Online

Connect-ExchangeOnline -UserPrincipalName <your_admin@domain.com>

Replace <your_admin@domain.com> with your actual email (must have permissions).

4. Set Out Of Office (Automatic Replies)

Modify the script below to edit your preferred internal/external Automatic Replies and your preferred start and end times. Ensure you set the correct path to the CSV file you created in Step 1.

Import your CSV File containing your Users UPNs

# Import CSV file containing user email addresses
$users = Import-Csv -Path "C:\Path\To\Emails.csv"

Define your options (date/time/messages)

# Define Out of Office settings
$InternalMessage = "School is currently closed until the 7th January 2025, I will respond on our return"
$ExternalMessage = "School is currently closed until the 7th January 2025, I will to your email after this date. If your email relates to GDPR, or SARs specifically please email DPO@yourdomain.com for a response within 72 hours."
$StartDate = "2024-12-19 12:30PM"
$EndDate = "2025-01-07 07:00AM"

Apply Out Of Office to all users

# Loop through each user to set Automatic Replies
foreach ($user in $users) {
    Write-Host "Setting Out of Office for: $($user.UserPrincipalName)"

    Set-MailboxAutoReplyConfiguration -Identity $user.UserPrincipalName `
        -AutoReplyState Scheduled `
        -StartTime $StartDate `
        -EndTime $EndDate `
        -InternalMessage $InternalMessage `
        -ExternalMessage $ExternalMessage `
        -ExternalAudience All

    Write-Host "Out of Office configured for: $($user.UserPrincipalName)"
}

Verify Out Of Office has applied

You can verify the out of office has applied by opening one of your users mailboxes and heading to the Automatic Replies section in Settings.

If you do not have permission for this, or do not want to, you can also check it has applied using the CMDlet below.

Get-MailboxAutoReplyConfiguration -Identity user1@domain.com

 

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply

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