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

Sometime you can see this message, when you try to join computer to the domain – even server.

 

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

The massage is clear – so solution is to execute:

 

dsregcmd /status
DSRegCmd /Leave
dsregcmd /status