Azure Virtual Machine PowerShell samples

The following table provides links to PowerShell script samples that create and manage Windows virtual machines (VMs).

Create virtual machines
Quickly create a virtual machine Creates a resource group, a virtual machine, and all related resources, with a minimum of prompts.
Create a fully configured virtual machine Creates a resource group, a virtual machine, and all related resources.
Create highly available virtual machines Creates several virtual machines in a highly-available and load-balanced configuration.
Create a VM and run a configuration script Creates a virtual machine and uses the Azure Custom Script extension to install IIS.
Create a VM and run a DSC configuration Creates a virtual machine and uses the Azure Desired State Configuration (DSC) extension to install IIS.
Upload a VHD and create VMs Uploads a local VHD file to Azure, creates an image from the VHD, and then creates a VM from that image.
Create a VM from a managed OS disk Creates a virtual machine by attaching an existing Managed Disk as OS disk.
Create a VM from a snapshot Creates a virtual machine from a snapshot by first creating a managed disk from the snapshot and then attaching the new managed disk as OS disk.
Manage storage
Create a managed disk from a VHD in the same or a different subscription Creates a managed disk from a specialized VHD as an OS disk, or from a data VHD as a data disk, in the same or a different subscription.
Create a managed disk from a snapshot Creates a managed disk from a snapshot.
Copy a managed disk to the same or a different subscription Copies a managed disk to the same or a different subscription that is in the same region as the parent managed disk.
Export a snapshot as a VHD to a storage account Exports a managed snapshot as a VHD to a storage account in a different region.
Export the VHD of a managed disk to a storage account Exports the underlying VHD of a managed disk to a storage account in a different region.
Create a snapshot from a VHD Creates a snapshot from a VHD and then uses that snapshot to create multiple identical managed disks quickly.
Copy a snapshot to the same or a different subscription Copies snapshot to the same or a different subscription that is in the same region as the parent snapshot.
Secure virtual machines
Encrypt a VM and its data disks Creates an Azure key vault, an encryption key, and a service principal, and then encrypts a VM.
Monitor virtual machines
Monitor a VM with Azure Monitor Creates a virtual machine, installs the Azure Log Analytics agent, and enrolls the VM in a Log Analytics workspace.
Collect details about all VMs in a subscription with PowerShell Creates a csv that contains the VM Name, Resource Group Name, Region, Virtual Network, Subnet, Private IP Address, OS Type, and Public IP Address of the VMs in the provided subscription.