Learn how to domain join your Azure DevTestLab VM to with an Active Directory Domain Controller using a powershell artifact. We’ll trigger this process from VSTS. The private artifact repository will also be available & exposed in DevTestLab for virtual machines in the lab.

Scenario

While provisioning a virtual machine in the AzureDevTest Lab you would like the newly provisioned virtual machine to be joined up to an existing Active Directory Domain Controller. This can be achieved by running a PowerShell script, that is wrapped up as an artifact. This artifact can be exposed in the DevTestLab via a private artifact repository.

AzureDevTestLabs Join Domain Scenario

In this blogpost I’ll show you how you can leverage a private artifact repository which intern uses powershell script to join your newly created Azure virtual machine in Azure DevTest Lab to an existing active directory domain.

Domain Join Artifact

The JoinDomain PowerShell script and Artifactfile json file is available for download on my gitHub repository

Download the artifact and use the instructions here to set up your private artifact repository. DevTestLabs support both Git and VSTS as artifact repository endpoints…

Once you have the private artifact repository set up and the Join Domain Artifact added, in the Azure Portal you should see something like this…

AzureDevTestLabs Join Domain Scenario

Plug in Domain Join Artifact to your ARM template

We’ll see how easy it is to add this private artifact script into your Azure DevTestVM ARM template. If you don’t already have an ARM template then refer to my blogpost here that shows you how to achieve this.

AzureDevTestLab ARM Template

In your AzureDevTestLab ARM template add the following three parameters…

    /* Join Domain Parameters */
        "Join_Domain_Domain": {
        "type": "string",
        "defaultValue": "myDomain.net"
        },
        "Join_Domain_UserName": {
        "type": "string"
        },
        "Join_Domain_Password": {
        "type": "string"

Supplement the artifact section of the template with the following artifact…

        "artifacts": 
        [          
            /* Join Domain */
            {
                "artifactId": "[resourceId('Microsoft.DevTestLab/labs/
                        artifactSources/artifacts', parameters('labName'), 
                        'privaterepo170', 'JoinDomain')]",
                        
                "parameters": 
                [
                    {
                        "name": "Domain",
                        "value": "[parameters('Join_Domain_Domain')]"
                    },
                    {
                        "name": "UserName",
                        "value": "[parameters('Join_Domain_UserName')]"
                    },
                    {
                        "name": "Password",
                        "value": "[parameters('Join_Domain_Password')]"
                    }
                ]
            }
        ]

Commit the changes to the repository…

Provision a new virtual machine in DevTestLab & trigger Join Domain artifact

I will use VSTS to trigger the deployment of the Azure DevTestLab ARM template. If you don’t want to use VSTS, you could deploy from this template directly from the Azure portal. In case you want to use VSTS to deploy a new Virtual Machine in an existing Azure DevTestLab then follow these instructions

Ammend the build definition to include the values for the three variables added to the ARM template.

VSTS AzureDevTestLab trigger new VM deloyment

Ensure that you add these variables into the template parameters section of the task.

VSTS AzureDevTestLab trigger new VM deloyment

Trigger a new build to create a new VM in an Azure DevTestLab to provision a new VM that runs the private artifact to domain join the newly provisioned virtual machine…

Validate that the JoinDomain artifact worked successfully

To validate the execution of the JoinDomain artifact navigate to the resource group of the newly deployed virtual machine. Click on deployments from the settings blade to load the history of all deployments that have taken place against this resource group.

VSTS AzureDevTestLab trigger new VM deloyment

The deployments blade will show you the full history of all deployments as well as the details of the artifacts run up against the resource group. You also have the ability to rerun the deployments of the artifacts from here. As you can see in the below screen shot, it is also possible to see the actual parameters passed to the artifact.

VSTS AzureDevTestLab trigger new VM deloyment

Voila! Now that the artifact has successfully been run, you’ll see the virtual machine registered in active directory under the computers OU. You will also be able to use domain credentials to log into the virtual machine.

VSTS AzureDevTestLab trigger new VM deloyment

Check out other posts on AzureDevTest labs:

Happy Deployments!

Tarun

Related Posts

About Tarun Arora

Tarun Arora is obsessed with high-quality working software, DevOps, Continuous Delivery and Agile. His core strengths are Azure, VSTS, PowerShell, SQL and WPF. He is a Microsoft MVP in Visual Studio Development Tools and the author of 'DevOps & ALM with TFS 2015'.