Unjoin VM’s from Azure AD before they are added to an AVD Host Pool.

Unjoin VM’s from Azure AD before they are added to an AVD Host Pool.



 Jun 29 2021

On occasions, when using Sysprep to generalize an image, the device remains Azure AD Joined.

This causes that the AVD operation "Add virtual machines to a host pool" fail with error code 2700.


This feedback is to request that AVD scripts/code behind this operation can handle this scenario and unjoin the device from Azure AD before it gets domain joined.


You can find if a device is joined to Azure AD by checking the attribute AzureAdJoined after executing in the command prompt:

dsregcmd.exe /status


If it is, we must execute this other command to unjoin it: dsregcmd /leave /verbose /debug

This can be either before running Sysprep again and capturing the new image for AVD.

Or after the VM failed to get created in the hostpool. (Which requires us to join the VM in the domain and install the AVD agents manually).


The following message is seen when this issue happens:


'displayStatus': 'Provisioning failed',

'message': 'ERROR - Failed to join domain='contoso.com', ou='DC=contoso,DC=com', user='username@contoso.com', option='NetSetupJoinDomain' (#1 meaning 'User Specified without NetSetupAcctCreate'). Error code 2700'


This is the description of error code 2700:

This machine is already joined to a cloud domain and cannot be subsequently joined to an Active Directory domain


And this is the article we used as reference: