Press "Enter" to skip to content

Learning vCO Part 2 – Creating Azure virtual machines

Hey All,

Welcome back to my learning vCO series of posts the posts will hopefully help to start to feel our way through vCO but to give base ideas that can be expanded on. Part 1 can be found here.
Today I thought how about we create a flow to create a windows Azure VM. Thought why not bring 2 virtualisation competitors and combine some technologies 🙂

There is a couple of pre reqs here.
1) You will need to have installed the powershell plugin into vCO, there are plenty of material out there on this.
2) you will need to run the “Add a powershell host” workflow to connect the “jumpbox” This requires winrm to be available.
2) you will need to have a “jump box” which will be your powershell plugins endpoint, this will allow us to run powershell commands remotely on this box. The Jump box will need the azure powershell modules installed which is extremely easy to install from by using the Web Platform Installer from MS.
3) Once done you will need to import your management cert onto the box navigate to once you have entered your azure account login details will download a sub name.publishstettings file.
4) Once you have this file open powershell as administrator and use the Import-AzurePublishSettingsFile filepath name.publishsettings. This will connect this jump server to your windows azure account.

There is other ways to authenticate but I found this one less hassle and if you wanted to automate something like this on a larger scale you would have a dedicated endpoint like this.

Now time to get our flow on!!!

1) Lets make a new workflow and call it something that represents what we are trying to do in this case provision new Azure VM
Once created you should have a blank flow like the image below.
Screen Shot 2014-08-25 at 4.56.54 pm

2) Now we want to find the invoke powershell script that is located under the powershell folder and drag it onto out flow, You should now have something similar to the image below
Screen Shot 2014-08-25 at 4.57.37 pm

3) You will get prompted up the top to set up the workflows parameters, hit setup and change all the items to value or local variable. note the image below just shows the host as a value. I have pre-set this to our configured powershell endpoint, the rest should be set to value too.
Screen Shot 2014-08-25 at 4.58.20 pm

4) Next up we need to drag a scriptible task element from the left and give it a good name, in this case we will be creating the powershell script to feed into the invoke powershell workflow.
you should now have something like the below image
Screen Shot 2014-08-25 at 4.59.02 pm

5) Next up we hit the edit icon for the new script-able task and first up we need to create some parameters that we will want people to enter that will make up the script, So for starters lets just use VM name, Admin account for the VM, Admin pass for the VM and service name which is required to build an azure VM. These will all be created as a string. The below images show what you should now have.
Screen Shot 2014-08-25 at 5.01.32 pmScreen Shot 2014-08-25 at 5.02.27 pm

6) now for the output, we will need to make the output the pre existing script attribute as shown in the below image.
Screen Shot 2014-08-25 at 5.03.59 pm

7) Now onto the script where the magic happens, vCO uses java script so i need to create the powershell script I want to run line by line with while using the users inputed values. Here is the script that I whipped together for this post.

var tmpScript = '';

tmpScript +='import-module azure \n';
tmpScript +='$vmname= "' + vmName + '"\n';
tmpScript +='$instance ="Basic_A0" \n';
tmpScript +='$image = "" \n';
tmpScript +='$adminName = "' + adminAccount + '"\n';
tmpScript +='$pass = "' + adminPass + '"\n';
tmpScript +='$group = "vmegroup" \n';
tmpScript +='$serviceName = "' + serviceName + '"\n';
tmpScript +='$vm1 = New-AzureVMConfig -Name $vmname -InstanceSize $instance -Image $image \n';
tmpScript +='$vm1 | Add-AzureProvisioningConfig -Windows -AdminUserName $adminName -Password $pass \n';
tmpScript +='$vm1 | New-AzureVM -ServiceName $serviceName -AffinityGroup "vmegroup" \n';

script = tmpScript;

The instance and image are what I am using in this demo but there is nothing stopping you adding more and having a drop down list, the instance is basically the size of the VM, while image is the build image you are using.
The Affinity group is something you setup within azure other wise location can be used which says which datacenter you building in.
The system logs are just so I can see what happening.
Screen Shot 2014-08-25 at 5.04.44 pm

8) Because the invoke workflow is pre built we just need to make sure that the invoke workflow has the right inputs and outputs, It should look something like the image below.
Screen Shot 2014-08-25 at 5.05.42 pm

9) Now for this quick learning vCO post we will drag and drop another scriptible task out and call in debug output. but all I want to do here is print out the output. But taking this further you can manipulate the returned data and grab the dns name and port to rdp on etc to send back to the user. But for this we just want to see it.
So we add the input as the output and add one line in the script which is System.log(output);
Screen Shot 2014-08-25 at 5.08.55 pm
Screen Shot 2014-08-25 at 5.10.35 pm
Screen Shot 2014-08-25 at 5.11.05 pm

10) Ok time to let it flow!! click on debug and lets see if it works. You should be presented with the inputs that we wanted as per the below image.
Screen Shot 2014-08-25 at 5.16.16 pm

11) hit submit and see if it works!!
Screen Shot 2014-08-25 at 5.17.04 pm
Screen Shot 2014-08-25 at 5.22.57 pm

12) It worked!!!! you will notice with the output we can see that in the logs on the right as per the image below.
Screen Shot 2014-08-25 at 5.22.47 pm

13) But did it really work lets log into azure and see if the service vcoautobuild and vm named vm002 have been created.
Screen Shot 2014-08-25 at 5.23.12 pm
Screen Shot 2014-08-25 at 5.28.25 pm

Wooooo all good provisioned and working

Next time we might look at expanding what we did here or what we did in part 1

can download the workflow here [wpdm_file id=4]



  1. GD
    GD November 4, 2015

    Great post and got me half way there 🙂 However I seem to have an issue where I can not execute all azure cmdlets. For example, get-azuresubscription works but I cannot create the VM as per your post. I can’t seem to get a list of vm with get-azurevm either. Everything seems to work fine if I execute script from PS host. Do you have any ideas? Why would certain cmdlets not work?


    • Scott Norris
      Scott Norris November 6, 2015

      Hi GD,
      Unfortunately I have not seen this issue. are you getting any errors on running the script? does it say the cmdlets dont exist? Does it fail when manually running the commands too?

      I have just rerun the same workflow and went through without a hitch. I had to change the image I was using as it no longer existed. Never tried listing the VMs though.


Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM BOT Question * Time limit is exhausted. Please reload CAPTCHA.