Create and manage virtual machines with DevTest Labs using the Azure CLI

This quick start will guide you through creating, starting, connecting, updating and cleaning up a development machine in your lab.

Before you begin:

  • If a lab has not been created, instructions can be found here.

  • Install CLI 2.0. To start, run az login to create a connection with Azure.

Create and verify the virtual machine

Create a VM from a marketplace image with ssh authentication.

az lab vm create --lab-name sampleLabName --resource-group sampleLabResourceGroup --name sampleVMName --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --authentication-type  ssh --generate-ssh-keys --ip-configuration public 

Note

Put the lab's resource group name in the --resource-group parameter.

If you want to create a VM using a formula, use the --formula parameter in az lab vm create.

Verify that the VM is available.

az lab vm show --lab-name sampleLabName --name sampleVMName --resource-group sampleResourceGroup --expand 'properties($expand=ComputeVm,NetworkInterface)' --query '{status: computeVm.statuses[0].displayStatus, fqdn: fqdn, ipAddress: networkInterface.publicIpAddress}'
{
  "fqdn": "lisalabvm.southcentralus.cloudapp.azure.com",
  "ipAddress": "13.85.228.112",
  "status": "Provisioning succeeded"
}

Start and connect to the virtual machine

Start a VM.

az lab vm start --lab-name sampleLabName --name sampleVMName --resource-group sampleLabResourceGroup

Note

Put the lab's resource group name in the --resource-group parameter.

Connect to a VM: SSH or Remote Desktop.

ssh userName@ipAddressOrfqdn 

Update the virtual machine

Apply artifacts to a VM.

az lab vm apply-artifacts --lab-name  sampleLabName --name sampleVMName  --resource-group sampleResourceGroup  --artifacts @/artifacts.json
[
  {
    "artifactId": "/artifactSources/public repo/artifacts/linux-java",
    "parameters": []
  },
  {
    "artifactId": "/artifactSources/public repo/artifacts/linux-install-nodejs",
    "parameters": []
  },
  {
    "artifactId": "/artifactSources/public repo/artifacts/linux-apt-package",
    "parameters": [
      {
        "name": "packages",
        "value": "abcd"
      },
      {
        "name": "update",
        "value": "true"
      },
      {
        "name": "options",
        "value": ""
      }
    ]
  } 
]

List artifacts available in the lab.

az lab vm show --lab-name sampleLabName --name sampleVMName --resource-group sampleResourceGroup --expand "properties(\$expand=artifacts)" --query 'artifacts[].{artifactId: artifactId, status: status}'
{
  "artifactId": "/subscriptions/abcdeftgh1213123/resourceGroups/lisalab123RG822645/providers/Microsoft.DevTestLab/labs/lisalab123/artifactSources/public repo/artifacts/linux-install-nodejs",
  "status": "Succeeded"
}

Stop and delete the virtual machine

Stop a VM.

az lab vm stop --lab-name sampleLabName --name sampleVMName --resource-group sampleResourceGroup

Delete a VM.

az lab vm delete --lab-name sampleLabName --name sampleVMName --resource-group sampleResourceGroup

Get started with Azure DevTest Labs

New to Azure? Create a free Azure account.

Already on Azure? Get started with your first lab in DevTest Labs.

Get started with Azure DevTest Labs in minutes