Getting an error when trying to setup Exchange Online ForwardingAddress in Azure Runbook

Nick 0 Reputation points


I am trying to setup an Azure Automation Runbook in which I convert a User Mailbox to a Shared Mailbox and setup a ForwardingAddress.

I setup all the permissions and converting the mailbox is working, setting a forwarding address throws the following error:

|Microsoft.Exchange.Data.Directory.InsufficientPermissionsException|Source doesn't have write permission to target DC:. Usually it indicates that target forest isn't an account partition of source forest. The user has insufficient access rights.

This is the script I am using:

Param (
 [string] $Employee = ""

Connect-ExchangeOnline -ManagedIdentity -Organization <DOMAIN>

$Mailbox = Get-Mailbox -Identity $Employee -ErrorAction SilentlyContinue

if ($Mailbox -eq $null) {}
    elseif ($Mailbox.RecipientTypeDetails -eq "SharedMailbox") {}
    else {
        Set-Mailbox -Identity $Employee -Type Shared -ErrorAction SilentlyContinue

Set-Mailbox -Identity $Employee -DeliverToMailboxAndForward $true -ForwardingAddress "<FORWARDING_ADDRESS>" 

If anyone knows a way to solve this please let me know.

Thank you!

Microsoft Exchange Online
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,160 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
522 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,222 questions
{count} votes