Monthly Archives: January 2015

Create a VM Network When Subscription is created in Windows Azure Pack with SMA part1

In this article i would like to describe how to create a VM Network under subscription of WAP (Windows Azure Pack) with using SMA when subscription is created but looks like its better to divide it two parts. Actually i m not very good about PS (powershell) and this is the first time use PS Workflow if you are like me, its better to start to read Microsoft Scripting Guy article first.

Shortly Azure Pack SMA is one of the good think i have ever seen after PowerShell for Microsoft. Shortly its a automation or orchestration tool . To install it please read this article from Romain Serre.

Actually you can find out a lot of article about SMA but i believe that this article different is explain something more clear for newbies like me.

First login WAP Service Management Portal, “AUTOMATION” section you will find out all things about create runbooks.

Screen Shot 2015-01-30 at 23.33.50


To create a runbook , press to New-> RUNBOOK -> QUICK CREATE

Screen Shot 2015-01-30 at 23.36.15


Set any name how you want, description but most important part is TAGS section , it should be “SPF” always , i will explain it a bit latter, but first important thing is never forget to tag your runbook.

Second important thing when you start to develop your workflow code pls do not change the workflow name latter, because for make a test you will run you runbook and an error will be appear that workflow name is different then what you run . If you would like to change the workflow name pls create a new workflow how you want and copy/past your code there.

After you create your first runbook pls filter it and be ready to edit for example , you can see that i clicked RUNBOOKS from top of the page and filter my runbook. I have some old runbooks and one of them is suspended other completed and newly created runbook is appeared never run, zero job and not published.

its very clear that to use runbook you need to publish, without publish your runbook it will never appear.
3rd important thing is when you develop your runbook it should never expect something from you when its run (means interaction like answer something yes or no , wait some input from console),  if its then you should see such exception and runbook status will be suspended, i will show you from where you can see the such exception and script out

Screen Shot 2015-01-30 at 23.53.35

Screen Shot 2015-01-30 at 23.47.03

Click on your create runbook and wait for new screen appear

Screen Shot 2015-01-31 at 00.11.32

Very easy you can fallow your runbook how many times its run , status and some other informations. Click “AUTHOR” and wait a new screen appear and then click “DRAFT” because we have not published something yet, need to write some code.

Screen Shot 2015-01-31 at 00.15.25

WAP have an editor, for example you can see that it can automatically manage () and {} also after you start to set variables it will auto complete it when you need it next time.

Now start to talk about example code below;

We know that we created a VahoTest runbook (or your one) and next we will care about param section.

Param section manage parameters but i really confused and couldn’t understand well i saw some parameters like $resourceObject and params, because they are different then what you set a parameter. For example you can set a parameter like Name, like “param ([string]$name)” and you can request parameter “VahoTest -name something” but $resourceObject and params are little different. Actually i write down such script to understand whats inside and after all i saw that they carry many key and value for different events.

I have to explain that SMA provide event base runbook execution, we will see it shortly and configure  do something when VM is created or do something when subscription create or do another thing when something deleted.



Screen Shot 2015-01-31 at 00.55.17


VMNetwork creation event happened and $resourceObject and params are carry something. You will see the full things when execute the script on your side.

InlineScript, workflows do not support all powershell cmdlets because of that InlineScript section comes to rescue, you can use it for commands which are not supported by workflow.

To access variables out of InlineScript section you need to use $USING:

Here maybe its good time to read something about workflow limitations.

Last lines are about testing and troubleshooting , for more please read this article.

After copy/past the code below, save it then click “PUBLISH” button. You will see that now nothing under “DRAFT” and its moved to “PUBLISHED” . When you want to edit again, come to “DRAFT” and click “EDIT RUNBOOK”

workflow VahoTest
        Foreach ($param in $params)
        Foreach ($resources in $resourceObject)
    write-output (Get-Date)
    write-warning "Warning Message"
    write-error "Error Message"
    write-verbose "Verbose Message"

Screen Shot 2015-01-31 at 01.18.58

Now time to assign runbook for any type of event we need, In my example above playing with “VM CLOUDs” . Click “AUTOMATION” link, you can see already created things.

In my example i want to execute runbook when VMM start to create VM Network (its easy then create a subscription or VM 🙂 ). You can imagine anything you want, for example its a good exercise to see what key/values are passed to $resourceObject and params for different kind of events

Screen Shot 2015-01-31 at 01.24.03

Please go to WAP from tenant portal try to create a VM Network manually, you will see that SMA will trigger the runbook , back to the admin portal find runbook , click on it and then click “JOBS” , check the job output. Thats it !

Screen Shot 2015-01-31 at 01.47.44

Now we are ready to switch part 2