FIX: Adding server to local domain This device is joined to AzureAD

Windows Server 2022 and Azure AD joined…

I’ve never worked with Windows Server 2022 before and it’s been a while since I’ve worked on a server at all, but for a new feature within our product I needed an on-premise or hybrid environment with a Domain Controller and Hybrid Worker (Azure Automation).
While adding my Hybrid Worker to the domain, I got an error that I didn’t expect.

This device is joined to Azure AD. To join an Active Directory domain, you must first go to settings and choose to disconnect your device from your work or school.

Well, I checked the option ‘Login with Azure AD‘ when creating the virtual machine in Azure and I had to figure this out.

FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD.
FIX: The following error occurred attempting to join the domain

The tutorial below will help you solve this problem.


Let’s fix This device is joined to Azure AD

There are 3 possibilities you can try, the first of which didn’t work for me and the last one is a bit more rigorous.
On Windows Server 2022 you don’t have the option to access your work or school account like you do on Windows 11.


Option 1 – Disconnect your device from your work or school

Go to Settings and search for Disconnect your device from your work or school.

FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD.
FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD.

Try this option, for me nothing happened after clicking the option, hopefully you will have better luck.

After that, try to join the server to the domain again.


Option 2 – Use the command-line with DSRegCmd

Open Command prompt as an administrator and run the following command:

DSRegCmd /Leave

This will remove any association with a work or school environment.

More about DSRegCmd: Troubleshoot devices by using the dsregcmd command – Microsoft Entra | Microsoft Learn


Option 3 – Remove the AADLoginForWindows extension from your virtual machine

  • Go to the Azure Portal and open your Virtual Machine
  • Search for Extensions in the menu
  • Click on AADLoginForWindows and click Uninstall
FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD.
FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD.

Full error message

Computer Name / Domain Changes

The following error occurred attempting to join the domain “”:

This device is joined to Azure AD. To join an Active Directory domain, you must first go to settings and choose to disconnect your device from your work or school.

FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD. To join an Active Directory domain, you must first go to settings and choose to disconnect your device from your work or school.
FIX: The following error occurred attempting to join the domain: This device is joined to Azure AD. To join an Active Directory domain, you must first go to settings and choose to disconnect your device from your work or school.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

Leave a Reply

Your email address will not be published. Required fields are marked *