Virtual Machine Automation Samples
Explore these code samples to learn how to automate various tasks related to Azure Virtual Machines using different SDKs and tools.
Deploy a VM using ARM Templates
Learn how to deploy a Linux or Windows VM using Azure Resource Manager (ARM) templates. This is a fundamental step for infrastructure as code.
View SampleAutomate VM Start/Stop with Azure CLI
Discover how to use the Azure Command-Line Interface (CLI) to programmatically start and stop your virtual machines, optimizing costs.
az vm stop --resource-group MyResourceGroup --name MyVM
az vm start --resource-group MyResourceGroup --name MyVM
View Sample
Scale VMs using Azure PowerShell
Understand how to automatically scale your virtual machine scale sets up or down based on performance metrics using Azure PowerShell scripts.
$vmss = Get-AzVmss -ResourceGroupName "MyResourceGroup" -VMScaleSetName "MyVMSS"
$vmss.Sku.Capacity = 5
Update-AzVmss -ResourceGroupName "MyResourceGroup" -VMScaleSetName "MyVMSS" -VirtualMachineScaleSet $vmss
View Sample
Create VM Disks and Attach to VM
This sample demonstrates how to create managed disks and attach them to an existing virtual machine using the Azure SDK for Python.
View SampleRun a Script on a VM using Custom Script Extension
Learn to execute custom scripts on your Azure VMs after deployment using the Custom Script Extension for Windows and Linux.
View Sample