Cannot join an Active Directory due to Azure AD connection.

When trying to join an Active Directory domain and you see the message:
"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"
run the following in an elevated cmd window:
DSRegCmd /Leave