<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mirko</title>
    <description>The latest articles on DEV Community by Mirko (@paxol).</description>
    <link>https://dev.to/paxol</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1029666%2F0aa0e123-97e7-4193-92e3-b0876d12d268.jpeg</url>
      <title>DEV Community: Mirko</title>
      <link>https://dev.to/paxol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paxol"/>
    <language>en</language>
    <item>
      <title>Updating MOERA Address for AD Connect Synchronized User in 2024</title>
      <dc:creator>Mirko</dc:creator>
      <pubDate>Mon, 21 Oct 2024 08:18:44 +0000</pubDate>
      <link>https://dev.to/paxol/updating-moera-address-for-ad-connect-synchronized-user-in-2024-125i</link>
      <guid>https://dev.to/paxol/updating-moera-address-for-ad-connect-synchronized-user-in-2024-125i</guid>
      <description>&lt;p&gt;Let's say that you want to change the username and email of a user inside your Microsoft Entra ID tenant. &lt;br&gt;
You can change the username easyly from Microsoft 365 admin center, and the primary email address as well, but what about the &lt;code&gt;@&amp;lt;your-domain&amp;gt;.onmicrosoft.com&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;That's the MOERA address, Microsoft Online Email Routing Address, and for whatever reason, you can't change it for "on-prem" accounts but you can for "cloud only" accounts.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Plan
&lt;/h2&gt;

&lt;p&gt;Here’s what you need to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert the user to a cloud-only account&lt;/li&gt;
&lt;li&gt;Change the username and email address, including MOERA&lt;/li&gt;
&lt;li&gt;Convert the user to a on-prem account again&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;This procedure is not officially supported by Microsoft, so proceed at your own risk. While I have tested it within my company, I am not an expert and cannot be held responsible for any errors or issues that may arise.&lt;/p&gt;

&lt;p&gt;Please, before continuing, read &lt;a href="https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/howto-troubleshoot-upn-changes" rel="noopener noreferrer"&gt;Plan and troubleshoot User Principal Name changes in Microsoft Entra ID&lt;/a&gt; from Microsoft documentation.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Procedure
&lt;/h2&gt;

&lt;p&gt;I'll show you the steps using a test account called "Bob Migration". I'll change the username from &lt;code&gt;b.migration.ext@&amp;lt;redacted-domain&amp;gt;&lt;/code&gt; to &lt;code&gt;b.migration@&amp;lt;redacted-domain&amp;gt;&lt;/code&gt;. Here is a screenshot to show the starting situation in Microsoft 365 admin center:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkvfxu6k767ve8n79d3l3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkvfxu6k767ve8n79d3l3.png" alt="User in Microsoft 365 admin center" width="800" height="133"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Assign directly a license
&lt;/h3&gt;

&lt;p&gt;To ensure that the user keeps the Outlook and Teams license during the whole process it is better to have a direct assignment instead of inheriting a license from a group. In this case I use a Microsoft 365 Business Basic.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Move the user to a non-sync OU
&lt;/h3&gt;

&lt;p&gt;In Active Directory, move the user to a non-sync OU. This has the effect of moving the user to the recycle bin of Entra ID (i.e. the user will be soft deleted).&lt;br&gt;
Remember to force the Azue AD Connect sync:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start-ADSyncSyncCycle -PolicyType Delta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Restore the user from the recycle bin
&lt;/h3&gt;

&lt;p&gt;Now you need to restore the user from the recycle bin. Do it from the Azure Portal, so you are not forced to set a new password.&lt;br&gt;
Navigate to "Microsoft Entra ID" -&amp;gt; "Users" -&amp;gt; "Deleted users", search for the user to restore, select it and click "Restore users".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffbfmfne8dmk27ww54tdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffbfmfne8dmk27ww54tdg.png" alt="Restore the user from the recycle bin" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Change the email address of the user's mailbox
&lt;/h3&gt;

&lt;p&gt;Go to Exchange admin center and open the user's mailbox details.&lt;br&gt;
Here click on "Manage email address types" and edit the primary SMTP address, the MOERA address (@.onmicrosoft.com) and the SIP address. If you want to receive the emails written at the old address, leave those in.&lt;br&gt;
Also change the mailbox alias by clicking on "Manage contact information".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs38mhdx7p5s9jdadld3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs38mhdx7p5s9jdadld3j.png" alt="Mailbox details" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcd32y6ejnnm48c6qdjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcd32y6ejnnm48c6qdjf.png" alt="After modifing the address types" width="590" height="346"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Change the username
&lt;/h3&gt;

&lt;p&gt;In Microsoft 365 admin center open the user details panel and click on "Manage username and email":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9gjh61hh8iu6jx1ql2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9gjh61hh8iu6jx1ql2q.png" alt="User details" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here change the "Primary email address and username" and the alias *@.onmicrosoft.com. The old username will be added as an alias. You can leave it if you want to receive the emails written at the old address.&lt;br&gt;
Once you are done click on save changes.&lt;/p&gt;
&lt;h3&gt;
  
  
  6. Back to Active Directory, change attributes to match the cloud account
&lt;/h3&gt;

&lt;p&gt;Open the user in Active Directory and change:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Under the "Account" tab, the user logon name to match the new username, without the @ part&lt;/li&gt;
&lt;li&gt;Under the "Attribute editor" tab, the proxyAddresses field to match the addresses set in "Manage email address types" in step 4.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  7. Time to restore the sync from Active Directory to Entra ID
&lt;/h3&gt;

&lt;p&gt;In my tests I've found that if I simply sync the user again, by moving it to the correct OU, the status shown in Microsoft 365 admin center remains "cloud-only". Looking at the logs in Synchronization Service Manager there was an error indicating that the writes to the "onPremise*" attributes had failed. All other operations were successful, including adding the user to other groups, but the synchronization status continued to display as "cloud-only".&lt;/p&gt;

&lt;p&gt;At the end, I've tried to move to the recycle bin the user from Azure Portal and let the sync tool restore it, and it worked. &lt;em&gt;¡Órale! 🎉&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, to soft delete the user go to Azure Portal, navigate to the Users menu, open the user details and delete the user.&lt;/p&gt;

&lt;p&gt;From Active Directory, move the user to a syncing OU and force the sync.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start-ADSyncSyncCycle -PolicyType Delta
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the user should be restored with the new username and MOERA address. Wait 10-15 minutes for Entra ID to process the user, then you should be able to login into Outlook and Teams. This can take longer if the servers are under load, I've experienced waiting time up to 30 min.&lt;/p&gt;

&lt;p&gt;If you have trouble entering the app, clear the browser cookies and login into Outlook from outlook.office.com. If you have trouble with Teams, try to login from the desktop app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;I'm not an Active Directory expert, I'm a software engineer, but when I heared my collegues talking about this, having trouble with "Immutable IDs" and the synchronization status stuck at "cloud-only", I decided to challenge myself and my problem solving skills (and my patience).&lt;/p&gt;

&lt;p&gt;A huge thanks goes to my collegue &lt;a href="https://www.linkedin.com/in/lorenzo-scanu-392a9190/" rel="noopener noreferrer"&gt;Lorenzo Scanu&lt;/a&gt; and to a LinkedIn post that he found, &lt;a href="https://www.linkedin.com/pulse/how-change-moera-address-synchronized-user-object-frank-plawetzki/" rel="noopener noreferrer"&gt;How to change the MOERA address of synchronized user objects&lt;/a&gt;, that I've followed to come up with points 1-5.&lt;/p&gt;

&lt;p&gt;If you have any suggestion on how to improve this, please leave a comment. Maybe in the future I'll automate this process with a Powershell script.&lt;/p&gt;

&lt;p&gt;If you want to reach out you can text me on &lt;a href="https://www.linkedin.com/in/mirko-passoli/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or write an email to mirko.passoli &lt;code&gt;at&lt;/code&gt; gmail.com.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>entraid</category>
      <category>activedirectory</category>
    </item>
  </channel>
</rss>
