Jump to content

Recommended Posts

Posted

I don't think this is possible but is there a way to set all staff say to have an out of office reply with a set bit of text between say 5pm - 5am each day?

 

Lead DSL is asking, she wants to push helpful information for students like child line etc after hours if they e-mail a teacher.

 

I've told her no but if you can, someone on here probably knows how :)

Posted
We had this exact same thing. In the end staff just put 'My working hours are...' in the footer of their emails.
  • Thanks 1
Posted
if you automate it with powershell everyday would it not overwrite any out off office the user setup - probably wouldnt be a problem 99% of the time.
Posted
if you automate it with powershell everyday would it not overwrite any out off office the user setup - probably wouldnt be a problem 99% of the time.

 

I think it is one of those things that seems easy to do and a good thing to do, but the reality is somewhat different.

Posted (edited)

This seems doable - the following needs the beginning tweaked to load creds from file (that you save ahead of time [should be a one-time thing]). But it should work - setup an Office 365 group, make the people you want to receive the automated out of office message members, put the group name in the script and the message you want sent, then schedule to run each day from a server on-site:

 

# Connect to Exchange Online
$UserCredential = Get-Credential # Prompt for creds
Connect-ExchangeOnline -Credential $UserCredential # Connect to Exchange online

# Set variables
$GroupName = "365TestGroup" # Office 365 Group Name
$Members = Get-UnifiedGroupLinks -Identity $GroupName -LinkType Members # Get member of group
$OOFStartTime = (Get-Date).Date.AddHours(17) # Set Start time to today at 17:00 PM hours
$OOFFinishTime = (Get-Date).Date.AddDays(1).AddHours(5) # Set Finish time to tomorrow at 05:00 AM
$OOFMessage = "This is a test - I think you could use HTML here...." # OOF Message to be sent

# Loop through each member of the group and set OOF (if OOF not already set)
foreach ($Member in $Members) {
   $OOFStatus = Get-MailboxAutoReplyConfiguration -Identity $Member.PrimarySmtpAddress # Get current OOF settings

   if ($OOFStatus.AutoReplyState -eq "Scheduled") {
       # OOF is already set...
       Write-Host "OOF is already set for $Member" -ForegroundColor Yellow # Alert OOF already set
   } else {
       # OOF is not set...
       Set-MailboxAutoReplyConfiguration -Identity $Member.PrimarySmtpAddress -AutoReplyState Scheduled -StartTime $OOFStartTime -EndTime $OOFFinishTime -ExternalMessage $OOFMessage -InternalMessage $OOFMessage # Set OOF
       Write-Host "OOF is set for $Member" -ForegroundColor Green # Alert OOF has been set
   }
}

# Disconnect from Exchange Online
Disconnect-ExchangeOnline

 

It skips people that already have an out of office set too.

 

 

 

***EDIT***

Found the code for creds, I haven't tested this part - but this looks how I remember handling credentials from file in PowerShell scripts previously.

 

Save creds to file (should be able to run this just once to create the file):

$credential = Get-Credential # Prompt for creds
$credential | Export-CliXml -Path 'C:\My\Path\cred.xml' # Save creds to file

Then change line 2 of the PowerShell Script from:

[color=#222222]$UserCredential = Get-Credential # Prompt for creds[/color]

To:

$UserCredential = Import-CliXml -Path 'C:\My\Path\cred.xml' # Get creds from file

Edited by ThomL
  • Thanks 2
Posted
This seems doable - the following needs the beginning tweaked to load creds from file (that you save ahead of time [should be a one-time thing]). But it should work - setup an Office 365 group, make the people you want to receive the automated out of office message members, put the group name in the script and the message you want sent, then schedule to run each day from a server on-site:

 

# Connect to Exchange Online
$UserCredential = Get-Credential # Prompt for creds
Connect-ExchangeOnline -Credential $UserCredential # Connect to Exchange online

# Set variables
$GroupName = "365TestGroup" # Office 365 Group Name
$Members = Get-UnifiedGroupLinks -Identity $GroupName -LinkType Members # Get member of group
$OOFStartTime = (Get-Date).Date.AddHours(17) # Set Start time to today at 17:00 PM hours
$OOFFinishTime = (Get-Date).Date.AddDays(1).AddHours(5) # Set Finish time to tomorrow at 05:00 AM
$OOFMessage = "This is a test - I think you could use HTML here...." # OOF Message to be sent

# Loop through each member of the group and set OOF (if OOF not already set)
foreach ($Member in $Members) {
   $OOFStatus = Get-MailboxAutoReplyConfiguration -Identity $Member.PrimarySmtpAddress # Get current OOF settings

   if ($OOFStatus.AutoReplyState -eq "Scheduled") {
       # OOF is already set...
       Write-Host "OOF is already set for $Member" -ForegroundColor Yellow # Alert OOF already set
   } else {
       # OOF is not set...
       Set-MailboxAutoReplyConfiguration -Identity $Member.PrimarySmtpAddress -AutoReplyState Scheduled -StartTime $OOFStartTime -EndTime $OOFFinishTime -ExternalMessage $OOFMessage -InternalMessage $OOFMessage # Set OOF
       Write-Host "OOF is set for $Member" -ForegroundColor Green # Alert OOF has been set
   }
}

# Disconnect from Exchange Online
Disconnect-ExchangeOnline

 

It skips people that already have an out of office set too.

 

 

 

***EDIT***

Found the code for creds, I haven't tested this part - but this looks how I remember handling credentials from file in PowerShell scripts previously.

 

Save creds to file (should be able to run this just once to create the file):

$credential = Get-Credential # Prompt for creds
$credential | Export-CliXml -Path 'C:\My\Path\cred.xml' # Save creds to file

Then change line 2 of the PowerShell Script from:

[color=#222222]$UserCredential = Get-Credential # Prompt for creds[/color]

To:

$UserCredential = Import-CliXml -Path 'C:\My\Path\cred.xml' # Get creds from file

 

Fantastic! i'll give it a good test but from a read through it looks like it will do what i'm after

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...