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?
govindagoud
Oct 12, 2023Brass Contributor
az vm extension set command with the following parameters to join the VM to your domain:
--vm-name: The name of the VM that you created in the previous step.
--resource-group: The name of the resource group where the VM is located.
--name: The name of the extension. For Azure AD join, you need to use AADLoginForWindows.
--publisher: The publisher of the extension. For Azure AD join, you need to use Microsoft.Azure.ActiveDirectory.
--version: The version of the extension. For Azure AD join, you need to use 1.0.
--settings: The settings for the extension. For Azure AD join, you need to provide a JSON object with the following property:
"mdmId": The ID of your Azure AD tenant. You can find it by using az account show --query tenantId.
Example:
# Create an Azure VM
az vm create \
--name myVM \
--resource-group myRG \
--image Win2019Datacenter \
--admin-username azureuser \
--admin-password P@ssw0rd1234 \
--authentication-type password \
--size Standard_D2s_v3 \
--location eastus
# Join the VM to your domain
az vm extension set \
--vm-name myVM \
--resource-group myRG \
--name AADLoginForWindows \
--publisher Microsoft.Azure.ActiveDirectory \
--version 1.0 \
--settings '{"mdmId": "0000000a-0000-0000-c000-000000000000"}'
--vm-name: The name of the VM that you created in the previous step.
--resource-group: The name of the resource group where the VM is located.
--name: The name of the extension. For Azure AD join, you need to use AADLoginForWindows.
--publisher: The publisher of the extension. For Azure AD join, you need to use Microsoft.Azure.ActiveDirectory.
--version: The version of the extension. For Azure AD join, you need to use 1.0.
--settings: The settings for the extension. For Azure AD join, you need to provide a JSON object with the following property:
"mdmId": The ID of your Azure AD tenant. You can find it by using az account show --query tenantId.
Example:
# Create an Azure VM
az vm create \
--name myVM \
--resource-group myRG \
--image Win2019Datacenter \
--admin-username azureuser \
--admin-password P@ssw0rd1234 \
--authentication-type password \
--size Standard_D2s_v3 \
--location eastus
# Join the VM to your domain
az vm extension set \
--vm-name myVM \
--resource-group myRG \
--name AADLoginForWindows \
--publisher Microsoft.Azure.ActiveDirectory \
--version 1.0 \
--settings '{"mdmId": "0000000a-0000-0000-c000-000000000000"}'