title | description | ms.topic | ms.author | author | ms.date |
---|---|---|---|---|---|
Azure CLI Samples |
Learn about Azure CLI scripts. With these samples, you can create a virtual machine and then start, stop, and delete it in Azure Lab Services. |
sample |
rosemalcolm |
RoseHJM |
02/02/2022 |
This article includes sample bash scripts built for Azure CLI for Azure Lab Services.
Script | Description |
---|---|
Create and verify a virtual machine (VM) | Creates a Windows VM with minimal configuration. |
Start a VM | Starts a VM. |
Stop and delete a VM | Stops and deletes a VM. |
[!INCLUDE sample-cli-install]
[!INCLUDE quickstarts-free-trial-note]
All of these scripts have the following prerequisite:
- A lab. The script requires you to have an existing lab.
This Azure CLI script creates a virtual machine in a lab. The VM created based on a marketplace image with SSH authentication. The script then verifies that the VM is available for use.
:::code language="powershell" source="../../cli_scripts/devtest-lab/create-verify-virtual-machine-in-lab/create-verify-virtual-machine-in-lab.sh":::
This script uses the following commands:
Command | Notes |
---|---|
az group create | Creates a resource group in which all resources are stored. |
az lab vm create | Creates a VM in a lab. |
az lab vm show | Displays the status of the VM in a lab. |
This Azure CLI script starts a virtual machine in a lab.
:::code language="powershell" source="../../cli_scripts/devtest-lab/start-connect-virtual-machine-in-lab/start-connect-virtual-machine-in-lab.sh":::
This script uses the following commands:
Command | Notes |
---|---|
az lab vm start | Starts a VM in a lab. This operation can take a while to complete. |
This Azure CLI script stops and deletes a virtual machine in a lab.
:::code language="powershell" source="../../cli_scripts/devtest-lab/stop-delete-virtual-machine-in-lab/stop-delete-virtual-machine-in-lab.sh":::
This script uses the following commands:
Command | Notes |
---|---|
az lab vm stop | Stops a VM in a lab. This operation can take a while to complete. |
az lab vm delete | Deletes a VM in a lab. This operation can take a while to complete. |
Run the following command to remove the resource group, VM, and all related resources.
az group delete --name $resourceGroupName