Forum Discussion
experi18
Oct 05, 2023Brass Contributor
Azure CLI to join a domain
Hi, wich parameters should I add into my script to create Azure VM (Via CLI) in order to automatically join my domain?
experi18
Apr 14, 2024Brass Contributor
Guys, sorry If I got confused but, do I need to join the VM into the domain AFTER the VM is created, then I run a command via "Azure Run Command" via Portal, or can I join it into the domain while creating the machine?
- KennethMLApr 15, 2024Iron Contributor
Obviously, you cannot do it before it is created 🙂
If you deploy the VM using a template (e.g. ARM) you can add a JsonADDomainExtension resource to the template and the VM will be joined to AD Domain when it is created. You can also use Powershell or CLI to add the extension to the VM after creation.
You cannot do it using the Run Command feature in Azure portal as the script will run in Local System context and will (hopefully) not have permissions to join the domain.- experi18Apr 17, 2024Brass Contributor
KennethML oh yeah, sure, it is not possible before it is created hehehe
But I mean, in the proccess of the creation of the machine, is it possible that after the creation, the machine is already into the domain?- KennethMLApr 23, 2024Iron ContributorHi again.
If you deploy using template (ARM/Bicep/Terraform) the VM will be domain joined when the deployment is done.
If you add the extension to the VM using PowerShell or CLI, you will need to run the command after VM is created.
Hope it makes sense.