Skip to content

Instantly share code, notes, and snippets.

@LudovicOmarini
Last active August 13, 2021 09:46
Show Gist options
  • Save LudovicOmarini/b5d6a5b19a07d1b3fbeacf54f418f9ef to your computer and use it in GitHub Desktop.
Save LudovicOmarini/b5d6a5b19a07d1b3fbeacf54f418f9ef to your computer and use it in GitHub Desktop.
The script create a exchange powershell session and browse an external list from file to set an o365 out of office message for every occurences on the file between two datetime
<#
.SYNOPSIS
Set an out of office message for o365 users by list between two datetime.
.DESCRIPTION
The script create a exchange powershell session and browse an external list from file to set an o365 out of office message for every occurences on the file between two datetime
.EXAMPLE
Create a txt file with all the email adress you have to set an out of message with this form :
email@adress.com
email2@adress.com
email3@adress.com
Change the path on the script ($users).
Change the template message ($message).
Change the StartDate and EndDate, but be CAREFUL there is 2h of two hours difference with the office365 server from France
You can see the difference for your country by running the script with an incorrect email
and by checking the line "TimeStamp = 07/31/2020 10:28:44" returned.
Execute the script.
.\Set_O365_OutOfOffice_Message_By_List.ps1
#>
#Creation of the exchange powershell session
$O365 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'https://outlook.office365.com/powershell-liveid/' -Credential $MsolCred -Authentication Basic -AllowRedirection
$importcmd = Import-PSSession $O365 -CommandName @('Set-MailboxAutoReplyConfiguration') -AllowClobber
#Get users list
$users = Get-Content "c:\pathtofile\file.txt"
#Message to send
$reply = '
<p>Hi,</p>
<p>Our company will be closed between the 1st january to the 31th december.</p>
<p>Mails will be never read by our team.</p>
<p>Cheers.</p>
<p><img src="https://static-cse.canva.com/blob/188460/canva_Signature_eskimoz.jpg" alt="" width="312" height="171" /></p>
'
#StartDate (MM/JJ/AAAA HH:MM:SS)
$StartTime = "01/01/2021 00:00:00"
#EndDate (MM/JJ/AAAA HH:MM:SS)
$EndTime = "12/31/2021 23:59:59"
#Loop to set the out of office message
$(foreach ($User in $Users) {
Set-MailboxAutoReplyConfiguration $User -AutoReplyState Scheduled -StartTime $StartTime -EndTime $EndTime -InternalMessage $reply -ExternalMessage $reply
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment