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.
- sudo su
- curl –silent –location https://rpm.nodesource.com/setup_4.x | bash –
- yum install -y nodejs
- npm install azure-cli -g
Once installed, type: azure
We are presented with the Azure Command line syntax overview:
[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
Command: azure login
We are then prompted to browse to http://aka.ms/devicelogin and enter the code
Next we are prompted for credentials (same auth for portal access), I used my AAD tenant credentials (firstname.lastname@example.org).
Confirmation via bash that we have logged in to our subcription
Now on to create a Windows VM, discover the syntax required:
Command: azure vm create -help
We see the command starts with: azure vm create, also dns-name and source image
Seems simple enough, constructed my commandline as follows:
Let’s see what happens:
Command: azure vm create drewcloud a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-20160518-en.us-127GB.vhd
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”
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 ;->