Help - I am unable to set an email alias in an Azure Runbook

Eric Neiner 51 Reputation points
2023-03-26T15:41:22.7766667+00:00

I have a need to create email aliases for exchange accounts. I am attempting to do this with an Azure Automation Runbook.

Connect-ExchangeOnline -ManagedIdentity -Organization "myorg.onmicrosoft.com" 
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
    $name = $Request.Body.Name
}
$user = $Request.Query.User
if (-not $user) {
    $user = $Request.Body.User
}
Get-Mailbox -Identity $name | Format-List  
#Set-Mailbox $user -EmailAddresses @{add="{"+$name+"@myorg.com"}

Get-Mailbox is working but set-mailbox is failing with Failed (Unauthorized).

I have a managed service account with Exchange online permissions. Which I know is working because Get-Mailbox is working.

Does anyone know what permissions need to be set on this to allow this from set-mailbox Azure powershell in this scenario?

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Sedat SALMAN 14,280 Reputation points MVP Volunteer Moderator
    2023-03-26T15:55:15.4733333+00:00

    you need to assign the "Exchange Recipients Management" role, which grants the necessary permissions to modify mailbox properties, including email addresses.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.