Set-AzureRmVMADDomainExtension fails to add VM to AD Domain
<p>The below VM extension fails to add VM to the domain.</p>

<p>It works fine when the ‘Computer Account’ exists in the AD. If the ‘Computer Account’ do not exist (New Server) it fails.</p>

<p>Set-AzureRmVMADDomainExtension -TypeHandlerVersion '1.0' -JoinOption 3 -DomainName $strDomainDNSName -ResourceGroupName $strRes_GrpName -VMName $strHostName -Credential $objCred -OUPath $strServerOU -Restart</p>

<p><strong>The join option 3 should complete the below actions.</strong></p>

<p>Value   Meaning
NETSETUP_JOIN_DOMAIN
0x00000001  Joins the computer to a domain. If this value is not specified, joins the computer to a workgroup.
NETSETUP_ACCT_CREATE
0x00000002  Creates the account on the domain.</p>

<p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa370433(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa370433(v=vs.85).aspx</a></p>

<p><strong>Found the below error details under Azure VM Extension:</strong></p>

<p>[</p>

<pre><code>{
    "code": "ComponentStatus/JoinDomainException for Option 3 meaning 'User Specified'/failed/1",
    "displayStatus": "Provisioning failed",
    "level": "Error",
    "message": "ERROR - Failed to join domain='MyAd.ad.company.co.uk', ou='OU=Computers,DC=MyAd,DC=ad,DC=company,DC=co,DC=uk', user='LocalAdmin@MyAD.ad.company.co.uk', option='NetSetupJoinDomain, NetSetupAcctCreate' (#3 meaning 'User Specified'). Error code 2",
    "time": null
}

{
    "code": "ComponentStatus/JoinDomainException for Option 1 meaning 'User Specified without NetSetupAcctCreate'/failed/1",
    "displayStatus": "Provisioning failed",
    "level": "Error",
    "message": "ERROR - Failed to join domain='MyAd.ad.company.co.uk', ou='OU=Computers,DC=MyAd,DC=ad,DC=company,DC=co,DC=uk', user='MGTAdmin@MyAd.ad.company.co.uk', option='NetSetupJoinDomain' (#1 meaning 'User Specified without NetSetupAcctCreate'). Error code 1332",
    "time": null
}
</code></pre>

<p>]  </p>