Let’s Level Set

So, let’s take a moment to see where we are in this mini-series. As introduced in Part 1.5, here is the collection of Intro to SMA posts so far: https://aka.ms/IntroToSMA

In this collection, you will find Part 1, Part 1.5, and a Utility Runbook Spotlight for VMM Custom Property Management (as well as a couple others not directly related to this mini-series). And while Part 1 and some of Part 1.5 are not pre-requisites for Part 2, I do strongly recommend them. The functionality explained in the VMM Custom Property Management post will be used extensively here in Part 2.

Got it, get to the content!

Sure.

This is Part 2 (of 2) in my mini-series for the SMA Runbook Spotlight on Virtual Machine Startup by Priority. While Part 1 was what I would consider a simple example, Part 2 dives into a couple more complex topics/features. We are still leveraging PowerShell v3 Workflow. We are still calling the workflows from SMA Runbooks. We are still even starting Hyper-V VMs through VMM.

The differences?

We are no longer relying on the Delay start up (seconds) field

We are no longer leveraging Start-Sleep with that Delay

We are no longer guessing when to start the next VM

What are we doing?

Storing the actual Startup Group in a VM scope level VMM Custom Property

Calculating the number of unique Startup Priority Groups from the Startup Group data stored/retrieved from the VM scope level VMM Custom Property Note Previously we were actually storing the number of Startup Priority Groups in a Cloud scope level VMM Custom Property

Leveraging the hash table data to Start VMs by Priority and verify VM Startup by checking for Hyper-V Integration Services

On With the Example(s)!

As “the process” for creating, testing, importing, running, etc., SMA Runbooks has been covered extensively in the previous posts, I will just jump right in…

Pre-Requisites

First order of business is to ensure your VMM environment is ready for these Workflows/Runbooks. As mentioned above, the VMM Custom Property Management Workflows/Runbooks are pre-requisites for this post’s example. This is due to the fact that this post’s example relies on VMM Custom Property Data. The VMM Custom Property Management Workflows/Runbooks help you to create Custom Properties and populate them with values. Those values will dictate the VM Startup Priority.

So, be sure to perform the following tasks (leveraging the VMM Custom Property Management Workflows/Runbooks is recommended, but not required):

Create a Custom Property at the VM scope level with the Name “Startup Group”

Create or find a Cloud with VMs you wish to start by priority group

Update the “Startup Group” Custom Property for each of the VMs in this Cloud

Test that you can retrieve the “Startup Group” Custom Property Values via PowerShell

Note Recent developments have made me realize that the Custom Property at the Cloud scope level is no longer necessary. Please see the next section for more details.

Recent Developments

Second order of business, is to admit that while the Get-VMMCustomPropertyValue.ps1 example that I provided in the pre-requisite post is good, it is not ideal for this solution (as it would take more distinct remote calls into VMM to leverage it as is, than I would like). So, what do I do when something needs to be improved?

Improve it!

Get-VMMCustomPropertyValuesforCloudVMs

Here we are, a new and improved version of that same PowerShell v3 Workflow / SMA Runbook. It has been optimized for this scenario. It takes in a smaller set of parameters and produces a more complex (yet more useful) output. Let’s take a look:

Note Because it performs a different function (different inputs and outputs), it does not replace its predecessor. In fact, both work rather nicely for their specific intentions. Let me put it this way, if you find a use for one, you will likely find a use for the other.

A quick rundown of what this new and improved version actually does:

Takes in fewer parameters, narrowing it down and simplifying

Output is more complex, yet has lots more data

Essentially, I needed a script that would take in a Cloud Name, query VMM for its associated VMs, and output a hash table of data based on VM name and related Custom Property. This is exactly what this script does. The hash table output can then be used to calculate (or measure) the unique count of priority startup groups to satisfy $StartupPriorityGroups. This makes the requirement of the Cloud level Custom Property obsolete (as mentioned in the previous section), but you can still leverage it if you would like.

Calling the Get-VMMCustomPropertyValuesforCloudVMs Workflow/Runbook

And while the execution of this PowerShell Workflow / SMA Runbook is handled in the below example, I figured I would place it here as well, in case you just want to leverage this bit of script:

Note I have included its initial usage to get an idea of how it can be leveraged during execution.

Start-VMs-by-Priority-Group

The following PowerShell v3 Workflow example has been implemented and tested in PowerShell ISE. It can be copy/pasted from here, or imported from the available PS1 file included in the TechNet Gallery Contribution (the link can be found below).

Note Some portions of this PowerShell do not function with the currently available Release Preview version of System Center 2012 R2 – SMA. The PowerShell itself was developed on currently released Windows Server 2012, so executing it against current technology works just fine, just not from within Release Preview SMA. I have tested it against later builds of SMA, and it works just fine. So, unfortunately, if you want to test this in SMA, you will have to wait until the final release build. See the “SMA Version Differences Example” section below for more information.

Calling the Start-VMs-by-Priority-Group Workflow/Runbook

The following PowerShell v3 Workflow contains the necessary script to call the above Runbook/Workflow example.

Note I have included two methods (the SMA Credential Variable method is commented out) for defining the $Creds variable which is a parameter for the Start-VMs-by-Priority-Group Workflow. Other methods are certainly possible and acceptable, feel free to leverage whichever works best for you. Also, this example PS is not part of the TechNet Gallery Contribution, as it is simply just an in-line PowerShell Workflow call.

SMA Version Differences Example

Here is an example of what works in both PowerShell v3 Workflow and current builds of SMA, but not the Release Preview version of SMA: