How to create Azure VM via CLI

Learn how to create an Azure Virtual Machines via the Command Line Interface

Posted: December 7, 2016
Tags: Azure  CLI 
Share this on

In a previous post, I had created all the Network bits needed to host the Virtual Machine. In this post, I will show you how I created the virtual machine itself.

Within azure there are blueprints that can be used to provision a pre-configured virtual machine. From the CLI there are command to get list of them

azure vm image list-publishers -l "East US"

From this list we can narrow down those that are windows based.

azure vm image list-offers -l "East US" -p "MicrosoftWindowsServer"

We can see the list of detail Windows Server blueprints SKUs

azure vm image list-skus -l "East US" -p "MicrosoftWindowsServer" -o "WindowsServer"

Within these SKUs there are specific builds

azure vm image list -l "East US" -p "MicrosoftWindowsServer" -o "WindowsServer" -k "2012-R2-Datacenter"

Let’s create a Windows Server virtual machine using the latest 2012 build

C:\Users\Steven>azure vm create -g "CLITestGroup" -n "TestVM" -l "East US" --nic-name "TestNIC" --os-type "Windows" --image-urn MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter:4.0.20161109 --admin-username "username" --admin-password "password"
info: Executing command vm create
+ Looking up the VM "TestVM"
info: Using the VM Size "Standard_DS1"
info: The [OS, Data] Disk or image configuration requires storage account
+ Retrieving storage accounts
info: Could not find any storage accounts in the region "eastus", trying to create new one
+ Creating storage account "cli50f9ddc54b6c7d39####" in "eastus"
+ Looking up the storage account cli50f9ddc54b6c7d39####
+ Looking up the NIC "TestNIC"
info: Found an existing NIC "TestNIC"
info: Found an IP configuration with virtual network subnet id "/subscriptions/####/resourceGroups/CLITestGroup/providers/Microsoft.Network/virtualNetworks/TestVNET/subnets/TestSubnet" in the NIC "TestNIC"
info: This NIC IP configuration has a public ip already configured "/subscriptions/####/resourcegroups/clitestgroup/providers/", any public ip parameters if provided, will be ignored.
info: The storage URI '' will be used for boot diagnostics settings, and it can be overwritten by the parameter input of '--boot-diagnostics-storage-uri'.
+ Getting virtual machine and/or extension image publishers (Location: "eastus")
+ Getting virtual machine extension image types (Publisher: "Microsoft.Compute" Location:"eastus")
+ Getting virtual machine extension image verions (Publisher: "Microsoft.Compute" Type:"BGInfo" Location:"eastus")
+ Creating VM "TestVM"
+ Installing extension "BGInfo", VM: "TestVM"
info: vm create command OK

We should not be able to connect to our created virtual machine. To do this we need to obtain the FQDN of the machine

C:\Users\Steven>azure network public-ip show -g "CLITestGroup" -n "TestPIP"
info:    Executing command network public-ip show
+ Looking up the public ip "TestPIP"
data:    Id                              : /subscriptions/####/resourceGroups/CLITestGroup/providers/Microsoft.Network/publicIPAddresses/TestPIP
data:    Name                            : TestPIP
data:    Type                            : Microsoft.Network/publicIPAddresses
data:    Location                        : eastus
data:    Provisioning state              : Succeeded
data:    Allocation method               : Dynamic
data:    IP version                      : IPv4
data:    Idle timeout in minutes         : 4
data:    IP Address                      : 13.92.39.###
data:    IP configuration id             : /subscriptions/####/resourceGroups/CLITestGroup/providers/Microsoft.Network/networkInterfaces/TestNIC/ipConfigurations/default-ip-config
data:    Domain name label               : sfdemo
data:    FQDN                            :
info:    network public-ip show command OK
Posted: December 7, 2016
Tags: Azure  CLI 
Share this on

I love delivering IoT solutions

Read more about what I do and our philosophy. Judge for yourself the work and results achieved for other clients.

Contact Me

back to top