Before you execute DevTest Labs related commands, set the appropriate Azure context by using the az account set command:
Azure CLI
az account set --subscription11111111-1111-1111-1111-111111111111
The command to create a virtual machine is: az lab vm create. The resource group for the lab, lab name, and virtual machine name are all required. The rest of the arguments change depending on the type of virtual machine.
The following command creates a Windows-based image from Azure Market Place. The name of the image is the same as you would see when creating a virtual machine using the Azure portal.
Azure CLI
az lab vm create --resource-group DtlResourceGroup --lab-name MyLab --name'MyTestVm'--image"Visual Studio Community 2017 on Windows Server 2016 (x64)"--image-type gallery --size'Standard_D2s_v3'--admin-username'AdminUser'--admin-password'Password1!'
The following command creates a virtual machine based on a custom image available in the lab:
Azure CLI
az lab vm create --resource-group DtlResourceGroup --lab-name MyLab --name'MyTestVm'--image"My Custom Image"--image-type custom --size'Standard_D2s_v3'--admin-username'AdminUser'--admin-password'Password1!'
The image-type argument has changed from gallery to custom. The name of the image matches what you see if you were to create the virtual machine in the Azure portal.
The following command creates a VM from a marketplace image with ssh authentication:
Azure CLI
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
You can also create virtual machines based on formulas by setting the image-type parameter to formula. If you need to choose a specific virtual network for your virtual machine, use the vnet-name and subnet parameters. For more information, see az lab vm create.
Verify that the VM is available.
Use the az lab vm show command to verify that the VM is available before you start and connect to it.
Azure CLI
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}'
To list artifacts available in a VM in a lab, run the following commands.
Cloud Shell - PowerShell: notice the use of the backtick (`) before the $ in $expand (i.e. `$expand):
Azure CLI
az lab vm show --resource-group<resourcegroupname>--lab-name<labname>--name<vmname>--expand"properties(`$expand=artifacts)"--query"artifacts[].{artifactId: artifactId, status: status}"
Cloud Shell - Bash: notice the use of the slash (\) character in front of $ in the command.
Azure CLI
az lab vm show --resource-group<resourcegroupname>--lab-name<labname>--name<vmname>--expand"properties(\$expand=artifacts)"--query"artifacts[].{artifactId: artifactId, status: status}"