Microsoft 365 and PowerShell
Set an out of office reply with PowerShell (Exchange Online)
On this page
Setting an out of office reply (automatic reply) from PowerShell is handy when someone is off unexpectedly and can’t do it themselves, when a member of staff has left, or when you need to change lots of mailboxes at once. It works the same way for user mailboxes and shared mailboxes.
First, connect to Exchange Online PowerShell. In every example below, replace user@yourdomain.co.uk with the mailbox you’re changing.
Check the current settings
Get-MailboxAutoReplyConfiguration -Identity user@yourdomain.co.uk
This shows whether replies are on (AutoReplyState), any scheduled start and end times, who external replies go to, and the current messages.
Turn on an out of office reply now
Set-MailboxAutoReplyConfiguration -Identity user@yourdomain.co.uk -AutoReplyState Enabled -InternalMessage "I'm out of the office today. For anything urgent, please contact Sam." -ExternalMessage "Thanks for your email. I'm out of the office today and will reply when I'm back." -ExternalAudience All
The reply stays on until you turn it off. Colleagues in your organisation get the internal message and everyone else gets the external one. -ExternalAudience controls who outside the organisation gets a reply:
- All: every external sender (the default).
- Known: only external senders in the mailbox’s contacts.
- None: no external replies at all. You can leave out
-ExternalMessagewith this option.
Schedule it for a set period
Use Scheduled with a start and end time, and the replies switch on and off by themselves. Long commands are easier to read and edit with splatting, where the settings go in a list first:
$ooo = @{
Identity = 'user@yourdomain.co.uk'
AutoReplyState = 'Scheduled'
StartTime = Get-Date '2026-12-23 17:00'
EndTime = Get-Date '2027-01-04 08:00'
InternalMessage = "I'm on leave until 4 January. For anything urgent, please contact Sam."
ExternalMessage = "Thanks for your email. I'm away until 4 January and will reply when I'm back."
ExternalAudience = 'All'
}
Set-MailboxAutoReplyConfiguration @ooo
Writing the dates as year-month-day with Get-Date avoids the classic UK/US mix-up, where 04/01 can mean 4 January or 1 April depending on the computer’s regional settings. Run Get-MailboxAutoReplyConfiguration afterwards to check the start and end times came out as you intended.
Decline meetings while they’re away
In Exchange Online, a scheduled reply can also block out the calendar and decline new meeting requests. Add these lines to the list above, before the closing bracket:
CreateOOFEvent = $true
OOFEventSubject = 'Out of office'
AutoDeclineFutureRequestsWhenOOF = $true
DeclineMeetingMessage = "I'm on leave until 4 January, so I've declined this meeting."
CreateOOFEvent adds an “Out of office” event covering the scheduled period, and AutoDeclineFutureRequestsWhenOOF declines any new meeting requests for that time with your message.
Turn it off
Set-MailboxAutoReplyConfiguration -Identity user@yourdomain.co.uk -AutoReplyState Disabled
The messages are kept, so you can turn the reply back on later without retyping them.
Formatting the message
Plain text works fine, but it all ends up on one line. For separate paragraphs, use simple HTML tags in the message:
-InternalMessage "<p>I'm on leave until 4 January.</p><p>For anything urgent, please contact Sam on 01234 567890.</p>"
Set replies on several mailboxes at once
Put the mailboxes in a list and loop through them, for example to cover an office closure:
$mailboxes = 'anna@yourdomain.co.uk', 'ben@yourdomain.co.uk', 'sales@yourdomain.co.uk'
foreach ($mailbox in $mailboxes) {
Set-MailboxAutoReplyConfiguration -Identity $mailbox -AutoReplyState Scheduled -StartTime (Get-Date '2026-12-24 12:00') -EndTime (Get-Date '2027-01-02 08:00') -InternalMessage "The office is closed until 2 January." -ExternalMessage "Thanks for your email. Our office is closed until 2 January and we'll reply when we're back."
}
To see which mailboxes currently have an out of office reply on or scheduled:
Get-Mailbox -ResultSize Unlimited | Get-MailboxAutoReplyConfiguration | Where-Object AutoReplyState -ne 'Disabled' | Select-Object Identity, AutoReplyState, StartTime, EndTime
Troubleshooting
- A sender only got one reply. That’s normal. Exchange replies to each sender once per out of office period, not to every email.
- External senders get nothing. Check
ExternalAudienceisn’t set to None, or to Known when the sender isn’t in the contacts, and that an external message is set. - The scheduled reply starts at the wrong time. Check the times with
Get-MailboxAutoReplyConfiguration, and use theGet-Date 'year-month-day'format shown above. - “The term ‘Set-MailboxAutoReplyConfiguration’ is not recognized”: you’re not connected to Exchange Online, or your account doesn’t have an Exchange admin role.
Microsoft’s Set-MailboxAutoReplyConfiguration reference lists every parameter.