Drew Robinson's Blog

Azure, Powershell and Security things

Creating a Windows VM using Azure cli

The following is a walk-through for creating a windows based azure vm using Azure cli (mac/linux).

Getting started, install the azure cli on linux or osx.

I used the following commands to install azure cli on centos 7.

  1. sudo su
  2. curl –silent –location https://rpm.nodesource.com/setup_4.x | bash –
  3. yum install -y nodejs
  4. npm install azure-cli -g

 

Once installed, type: azure

We are presented with the Azure Command line syntax overview:

azurecli

 

Syntax:

[bash prompt] azure | topic | verb | options

Example, to create a virtual machine: 

command: azure vm create 

So to get started, we first must login to our azure subscription

azurelogin

Command: azure login

azurelogin

We are then prompted to browse to http://aka.ms/devicelogin and enter the code 

azure-cli2

Next we are prompted for credentials (same auth for portal access), I used my AAD tenant credentials (user@domain.onmicrosoft.com).

msazurelogin

Successful login:

:azure-cli7

Confirmation via bash that we have logged in to our subcription

azurecli6

Now on to create a Windows VM, discover the syntax required:

Command: azure vm create -help

azurevmcreate

We see the command starts with: azure vm create, also dns-name and source image

vmcreate1

Seems simple enough, constructed my commandline as follows:

syntax

Let’s see what happens:

Command: azure vm create drewcloud a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-20160518-en.us-127GB.vhd

vmcreatenull

Joy not, we have to provide a username, also I want to make sure the deployment is provisioned in my existing storage account, also I want define the hostname at provisioning.. so I will have to provide additional parameters. Here is what I discovered:

-c = cloud service, create this vm in a cloud service

-g = username

-p = password

-n = virtual machine hostname

-u = blob url (note vhd path must be included)

-r = RDP enabled

Here is the final command for creating a Windows VM using Azure cli:

Command: azure vm create drewcloud a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-20160518-en.us-127GB.vhd -c drewcloud -g “meetupuser” -p “@MeetUP99” -n drewvm1 -u “https://.blob.core.windows.net/vhds/drewc.vhd”

vmcreateok

 

Note: The cloud service, username and password are all throwaway, this was a demo for a local azure user community group. You might also notice RDP was not enabled ;->