Share via

Automatically make proxyAddresses in Exchange different from the UPN

Anonymous
2023-09-06T22:54:27+00:00

Trying to figure out how to run a PowerShell script I can run in Azure Functions that modifies the proxyAddresses/EmailAddresses field in Exchange Online without changing the UPN in Azure.

I'm automating Office365 cloud account creation for my organization and I've run into quite the problem. Decision-makers above my head have made the decision that the primary email address must be A and the UPN must be B. Since this has already been implemented for some time, it would be hard to make a good case for changing it to where the UPN and primary email match like they are supposed to although I've brought it up a number of times.

The more I look into it, the more I wonder whether it's even possible. So far, I've tried the following:

Use an HTTP request to update the proxyAddresses field in Azure AD via Graph API. I found out that even with all read and write permissions, the proxyAddresses field is read-only due to being populated from Exchange. Evidently Exchange doesn't have a REST API for editing user information.

I've tried using this after signing into PowerShell manually and I got an error for it.

PS C:> Set-Mailbox -Identity $userPrincipalName -EmailAddresses $proxyAddresses

Set-Mailbox : A parameter cannot be found that matches parameter name 'EmailAddresses'.

At line:1 char:42

  • Set-Mailbox -Identity $userPrincipalName -EmailAddresses $proxyAddres ...
  •                                      ~~~~~~~~~~~~~~~ 
    
    • CategoryInfo : InvalidArgument: (:) [Set-Mailbox], ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,Set-Mailbox
Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-09-07T01:29:02+00:00

    Hi Caleb,

    Thanks for contacting us,

    I understand that you are trying to automate the Office 365 cloud account creation for your organization and you want to make the proxyAddresses in Exchange different from the UPN in Azure. I searched for some possible solutions and found the following information:

    • According to https://learn.microsoft.com/en-us/powershell/module/exchange/set-mailbox?view=exchange-ps, the Set-Mailbox cmdlet can be used to modify the email addresses of existing mailboxes in Exchange Online. The -EmailAddresses parameter accepts a list of email addresses that you want to assign to the mailbox. You can use the SMTP prefix to indicate the primary email address, and the smtp prefix to indicate the secondary email addresses. For example, you can use the following command to set *************** as the primary email address and ******************** as a secondary email address:

    Set-Mailbox -Identity *************** -EmailAddresses SMTP:***************,smtp:********************

    • However, if you want to set the primary email address to a different value than the UPN, you need to disable the email address policy for the mailbox first. The email address policy automatically generates email addresses for mailboxes based on their UPN and other attributes. To disable the email address policy for a mailbox, you can use the -EmailAddressPolicyEnabled parameter with a value of $false. For example, you can use the following command to disable the email address policy for ***************:

    Set-Mailbox -Identity *************** -EmailAddressPolicyEnabled $false

    • After disabling the email address policy, you can then use the -EmailAddresses parameter to set the primary email address to a different value than the UPN. For example, you can use the following command to set ********************* as the primary email address for ***************:

    Set-Mailbox -Identity *************** -EmailAddresses SMTP:*********************,smtp:***************

    • Note that disabling the email address policy will prevent any future changes to the UPN or other attributes from affecting the email addresses of the mailbox. If you want to re-enable the email address policy later, you can use the -EmailAddressPolicyEnabled parameter with a value of $true. For example, you can use the following command to re-enable the email address policy for ***************:

    Set-Mailbox -Identity *************** -EmailAddressPolicyEnabled $true

    I hope this helps!

    Regards, Sola

    Was this answer helpful?

    0 comments No comments