Skip to content

Instantly share code, notes, and snippets.

@DXPetti
Created April 4, 2020 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DXPetti/287bd65dd794b67f7a734fabfdf0a223 to your computer and use it in GitHub Desktop.
Save DXPetti/287bd65dd794b67f7a734fabfdf0a223 to your computer and use it in GitHub Desktop.
<#
.Synopsis
Backups up and sets the Out of Office message for all shared mailboxes
.DESCRIPTION
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.
.EXAMPLE
Set-SharedMbxOoo -Path C:\Temp\BackupOfOOO\ -Message "Hello there!"
.NOTES
Version: 1.0
Author: James Pettigrove
#>
function Set-SharedMbxOoo
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$false,
Position=0)]
[string]$Path = $PSCommandPath,
# Param2 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[string]$Message
)
Begin
{
#Load Exchange Powershell Module
if (! (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) )
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:Stop
}
}
Process
{
#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
}
}
}
Set-SharedMbxOoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment