Author Posts

June 13, 2018 at 1:53 am

Hi All,

Occasionally I get asked to set the Out of Office for one of the employees. The only way to do with in Office365 is to give myself full delegation rights to the users exchange account, log into their inbox and set it. I really hate this as it feels like an invasion of privacy to me. So I started looking into what I can do with PowerShell and came up with this.

Set-MailboxAutoREplyConfiguration -Identity xxx -AutoReplyState Scheduled -Confirm -StartTime "06/13/2018 08:00:00" -EndTime "06/13/2018 12:00:00" -InternalMessage "Testing Out Of Office Via Powershell"

Now this does turn on the OOF and sets the message accordingly, however it sets the time as 6PM to 10PM. Its not a timezone issue as I have tried it on my own PC and have tried another user in the office and they end up with the same time.

Can someone please help with where I am going wrong?

OK, I think it is converting from Australian time to US time 🙁 Does this mean I need to enter my times in US time or is there an easy way to convert the string to a US date/time string?

June 13, 2018 at 3:26 am

Alright I cheated for now since I need to get on to other stuff.

# Enter my admin account
$UserCredential = Get-Credential
# Log into Exchange Online with my Log in account and get the powershell module for Exchange
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
# Import this into my local session
Import-PSSession $Session

# echo output a message to user telling them to enter in UTC time
write-host "********************************************************************************************************************"
Write-host "All Dates and Times need to be in UTC time.  Eg, 06/12/2018 20:00:00 equals 6am on the 13th June"
write-host "********************************************************************************************************************"

# prompt for information
$Identity = read-host -Prompt "Account Name"
$StartDateTime = read-host -Prompt "Start Date (MM/DD/YYYY HH:MM:SS)" 
$EndDateTime = read-host -Prompt "End Date (MM/DD/YYYY HH:MM:SS)" 
$InternalMessage = read-host -Prompt "Internal Message"
$ExternalMessage = read-host -Prompt "External Message"

# Set the mailbox auto reply
Set-MailboxAutoREplyConfiguration -Identity $Identity -AutoReplyState Scheduled -Confirm -StartTime $StartDateTime -EndTime $EndDateTime -InternalMessage $InternalMessage -ExternalMessage $ExternalMessage 

# wait for user to hit any key incase there is an error
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');

June 13, 2018 at 4:15 am

Ok got it. Its using UTC time of course.

# Enter my admin account
$UserCredential = Get-Credential
# Log into Exchange Online with my Log in account and get the powershell module for Exchange
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
# Import this into my local session
Import-PSSession $Session

# echo output a message to user telling them to enter in UTC time
write-host "********************************************************************************************************************"
Write-host "All Dates and Times need to be in UTC time.  Eg, 06/12/2018 20:00:00 equals 6am on the 13th June"
write-host "********************************************************************************************************************"

# prompt for information
$Identity = read-host -Prompt "Account Name"
$StartDateTime = read-host -Prompt "Start Date (MM/DD/YYYY HH:MM:SS)" 
$EndDateTime = read-host -Prompt "End Date (MM/DD/YYYY HH:MM:SS)" 
$InternalMessage = read-host -Prompt "Internal Message"
$ExternalMessage = read-host -Prompt "External Message"

# Set the mailbox auto reply
Set-MailboxAutoREplyConfiguration -Identity $Identity -AutoReplyState Scheduled -Confirm -StartTime $StartDateTime -EndTime $EndDateTime -InternalMessage $InternalMessage -ExternalMessage $ExternalMessage 

# wait for user to hit any key incase there is an error
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');

June 13, 2018 at 12:16 pm

You can make this a good bit simpler and not require the user to enter in UTC. You can do something like this to do the conversion:

$UniversalTime = ($EnteredDateTime | Get-Date).ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss")

That has the bonus of permitting most recognisable input formats.

June 14, 2018 at 3:44 am

Thank you Joel, i will give this a go.

I have to write one soon to add a Guest User Email to a DL.