Selecting a Random Runbook Server – Part 2 – a Closer Look

It’s been quite a while since my last post.  I’ve had several people email me and ask for a closer look at selecting a random runbook server.

A bit of a review, refer to the previous post for reference.  But, I was curious about how you could genuinely select a RANDOM server rather than rely on a “primary” and or “secondary” that were “static”.  (Please read the disclaimer at the bottom of this post)

Since this is a closer look, I’ll try to keep things simple and include screen shots.

I will show you how to subscribe to and use data within the data bus.

First, a bit of design explanation.  For simplicity, there are two runbook servers.  Their names are “SCORCH01” and “SCORCH02”.  Tying into Jon Mattivi’s post, we will create two variables.

Here’s an example of creating the first variable “RBServer1”.


You should now have two variables as in the example below:



I have an initiation runbook that starts another runbook.  For an explanation of what an initiation runbook folder is, download this free book “Designing System Center Runbooks“from Microsoft.

The other runbook is invoked from the initiation runbook that runs a PowerShell script, queries groups for members, creates a report and emails it to a distribution list.

For the purpose of this blog post, we don’t care about the contents of the runbook that generates a report so that won’t be discussed.

I want to point something out here.  My initiation run book is NOT using a random server!  What I want to do is edit the properties of the runbook so that I am overriding the default roles and I add any and all servers I want to be able to run this.  The top server listed is the primary.  If the primary isn’t available, then the secondary is used.

Here is a screen shot showing the properties of my initiation runbook.  click the “Runbook Servers” tab, then override and select your servers to use when this RB runs.



The initiation runbook looks like this:


The activity “Run .Net Script” titled “Generate Random RB Server” is our primary focus here.

Type in your PowerShell script:


$RBServer = ($Server = “”,””) | Get-Random.


Now, you could add the data to subscribe the data.  The easy way is to RIGHT click and subscribe to the data.  So, as you type in the script after the first double quotes, right click the mouse.  Then, select your first variable.  Add the closing double quotes, then the comma, then the double quotes again, right click, subscribe, then close double quotes then right parenthesis.

That will give you this:


Now, DO NOT click the finish button yet.

Click the Published Data tab, click the Add button and enter in a new variable, type string, name “RBServer”.  This is what puts the returned data into the data bus so you can use it in any subsequent activities in your runbook(s).


The last activity in my initiation runbook is “Invoke Runbook”.  I’ve linked my runbook that I want to invoke.  Right click click in the “Runbook Servers” text field, select “Subscribe > Published Data”


Since my last activity was the activity that runs the PowerShell script, I don’t need to hunt for it.  But, if you have a more complicated script that has many activities, you HAVE to pay attention to the flow of your runbook.  You can only select published data that would have been generated prior to the point at which you are subscribing to the data…. after all, you can’t use data that isn’t established.

In this example, I am looking for the published data “RBServer”.  Select it and click ok.


Now, your dialogue box for “Invoke Runbook” should look like the this:



Now, when this initiation runbook runs, it generates a random server name, invokes a runbook on the server name selected by the PowerShell script.


A disclaimer?  What for?  Well, here’s why and what for.  There may be practical uses of this approach.  But, remember that I went after this with some curiosity following an Orchestrator class. But, this example is a very SIMPLE example.

So, we’ve used “HA” by adding multiple servers in the properties of the runbook.  We’ve generated a random runbook server… HOWEVER, if you pay close attention, my PowerShell script is nothing more than a simple method to select a random string from only two that I’ve provided.  That’s all it is!  I would not suggest using this example in production without a lot of improvements!

What if SCORCH01 is down?  The script doesn’t provide for any error handling or error checking either.

So, just take note.  To be much more robust, you’ll want to beef up that script quite a bit.  If your Orchestrator environment is built properly, you’ll have more than one runbook server for HA and load balancing.  To be honest, using the primary and secondary servers in the “Runbook Servers” tab on the properties of your runbook is probably sufficient.

The Amateur PowerShell Expedition – An Introduction

I’m one of those folks who learns like an elephant.  I admit, there are times when I have a pea-sized brain and I have a thick skull.  So, this stubborn 40-something guy of Polish stock (which is underlined by my stubbornness… just ask my wife) makes for some interesting learning experiences.  Sometimes, I just have to beat myself in the head with a skillet (i.e., looking at 10,000 examples of the same thing) before that light bulb goes off.  I have jump in 200 foot water with no hope of seeing land for weeks or months at a time and learn to swim.  Pick your analogy here.  Coding is not something I do on a regular basis.  I like the K.I.S.S. principle.  I’m always looking back at any code I do use and improving it when I find better ways to do something.

I’ve been an avid “amateur” programmer since the early 1980s.  I’ve dibbled and dabbled in BASIC, QBASIC, PASCAL, COBOL, misc batch file programming, VB,, C, C++, Java, and now PowerShell.  That leaky brain of mine has a big hole!  I’ve never programmed extensively.  I’ve never developed that true “Thinking in…” kind of brain that Bruce Eckel and others possess.  I just can’t “THINK” in code.

So, the posts in this category will be from that point of view.  From the “amateur” dibbler and dabbler perspective if you will.  I will never be one to profess to be an expert at anything.  I encourage your comments and responses to my posts and I will correct/improve code snippets so they may be of value to readers of this blog.

I will try to break things down and explain them from my point of view.