Bulk Backup and Set Out of Office Messages

We live in very interesting times at the moment. No doubt, anyone reading this has been touched by the effects of the spread of COVID-19 across the world.

One requirement that I had in response to the outbreak was to prepare for a full office shutdown. Part of this shutdown would require all of the businesses shared/group mailboxes to display a new Out of Office message to all external parties.

While this task in itself, isn’t too complicated to appear, if the time came to do so, I wanted to ensure that any existing Out of Office message and corresponding configuration was preserved. This way, upon business operations returning to their former state, the previous Out of Office message/configuration can be restored. In doing so, we are taking the burden of the customer to do this (I’m sure they have enough on their plate to catch up on).

So, without further ado, bring forth the Powershell:

Backups up and sets the Out of Office message for all shared mailboxes
Taking a path plus message as input, this cmdlet gets all current mailboxes in specific OU, loops
through and takes a backup of (if any) Out of Office message plus parameters defined for the message.
In the same loop, the message inputted earlier is then defined as a Enabled, External Audience Out of
Office message.
Set-SharedMbxOoo -Path C:\Temp\BackupOfOOO\ -Message "Hello there!"
Version: 1.0
Author: James Pettigrove
function Set-SharedMbxOoo
# Param1 help description
[string]$Path = $PSCommandPath,
# Param2 help description
#Load Exchange Powershell Module
if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 ErrorAction:SilentlyContinue) )
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 ErrorAction:Stop
#Get all Shared Mailboxes and loop through each mailbox
$Mbx = Get-Mailbox OrganizationalUnit "OU=Shared Mailboxes,OU=Users,DC=contoso,DC=co"
ForEach ($M in $Mbx)
Write-Host "Backing up auto-reply for shared mailbox:" $M.DisplayName
Get-MailboxAutoReplyConfiguration Identity $M.Alias | Export-Csv Path "$Path$($M.Alias).csv" NoTypeInformation
Write-Host "Setting auto-reply for shared mailbox:" $M.DisplayName
Set-MailboxAutoReplyConfiguration Identity $M.Alias ExternalAudience All AutoReplyState Enabled ExternalMessage $Message
view raw Set-SharedMbxOoo.ps1 hosted with ❤ by GitHub

Let’s break down a couple of important elements to the code.

First and foremost, my code is targeted at a Exchange 2010 (yes I know, don’t @ me) environment, therefore, I’m loading the Exchange 2010 snap-in:

        #Load Exchange Powershell Module
        if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) )
            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:Stop

Feel free to swap out with your version of Exchange that you will be targeting. I do warn you that YMMV. I’ve had random crashes loading or utilising the Exchange modules outside of the Exchange Shell. My recommendation would be to use this code with the Exchange shell versus a regular Powershell shell.

Next up, we need to get all mailboxes of the shared/group variety. Fortunately, the environment I am working on has keep these types to a specific OU, which I am targeting with:

        #Get all Shared Mailboxes and loop through each mailbox
        $Mbx = Get-Mailbox -OrganizationalUnit "OU=Shared Mailboxes,OU=Users,DC=contoso,DC=co"

Replace the OU with your equivalent. The alternative is to make use of Get-Mailbox‘s –RecipientTypeDetails parameter to specify the mailbox type, if you are making use of them in your environment.

Apart from the above two change you may need to make, all you need to do is run the cmdlet and provide both the path for the backup of current OOO message + configuration to be stored plus the new message and your set to go.

So backing up and setting a message in bulk is now straight forward to achieve in your organisation. How do we rollback our OOOs once things settle down and return to normal?

Look out for my next post to learn how.

Stay safe, stay indoors!

James Written by:

One Comment

Helpful? Have a question on the above?