Office 365 Forward on a Schedule

posted in: Office 365, Windows | 0

The ability to schedule users forwarding to another email box or group

I tried to do this based on email header information by day of the week but since Office 365 email generally uses UTC time that did not work.

The only way I found to get this to work was to use Power-Shell and use a Windows Task Scheduler. It is better to have your password encrypted there are examples out there about that.

This command DeliverToMailboxAndForward directs to either just forward
$false or to forward and save a copy in the local mailbox $true.

Enable Forwarding Script

$Username = “user@domain.com
$Password = ConvertTo-SecureString ‘password‘ -AsPlainText -Force
$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Set-Mailbox -Identity “MailBox Name” -DeliverToMailboxAndForward $true -ForwardingAddress forward@domain.com
Remove-PSSession $Session

Disable Forwarding Script

$Username = “user@domain.com
$Password = ConvertTo-SecureString ‘password‘ -AsPlainText -Force
$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Set-Mailbox -Identity “MailBox Name” -DeliverToMailboxAndForward $false -ForwardingAddress $Null
Remove-PSSession $Session