...building hybrid clouds that can support any device from anywhere
There comes a time when a project’s complexity increases to the point of requiring pre-requisites. The follow-up post to Automation–Service Management Automation Runbook Spotlight–Virtual Machine Startup by Priority (Part 1) is one of these instances. As described in Automation–Service Management Automation Runbook Spotlight–Virtual Machine Startup by Priority (Part 1.5), I am reintroducing the concept of data storage via VMM Custom Properties. In that post I explain the need for this post (the actual pre-requisite) and make a promise to deliver examples for the following tasks:
This is the post where I deliver on that promise.
The following PowerShell v3 Workflow examples have been implemented and tested in SMA. Each of them can be copy/pasted from here, or imported from the available PS1 files included in the TechNet Gallery Contribution (the link can be found below).
Note This example can be found in the SMA-VMMCustomPropertyManagement.zip as Create-VMMCustomProperty.ps1
Note This example can be found in the SMA-VMMCustomPropertyManagement.zip as Update-VMMCustomPropertyValue.ps1
Note This example can be found in the SMA-VMMCustomPropertyManagement.zip as Get-VMMCustomPropertyValue.ps1
Note This example can be found in the SMA-VMMCustomPropertyManagement.zip as Remove-VMMCustomPropertyValue.ps1
Note This example can be found in the SMA-VMMCustomPropertyManagement.zip as Remove-VMMCustomProperty.ps1
The following PowerShell v3 Workflows contain all the necessary scripts to call the above (5) Runbook/Workflow examples. In fact, since each example will likely be executed individually, the following script snippets have been broken up by atomic function (with common script portions included at the top).
Note Each of the specific example script calls below leverage an array of “:” delimited data which is parsed (split) and passed to the calls by specific array placement. You can certainly generate and pass data any way that you would like, this was just my way to encapsulate all the data necessary for the examples provided.
Note Workflow name (Execute-VMMCustomPropertyRunbooks) and variable usage ($Creds and $VMMServer) are provided as an example, and can be leveraged when calling the other script snippets listed below (as indicated by the commented portion). Also, Line 3 above ($Creds) leverages an SMA Credential Variable. Please refer to this blog post for more information on this type of variable (to be found in the Overview of the SMA Runbooks section of that post).
Note While the example directly above does work via PowerShell v3 Workflow, it does not function with the Preview Release of SMA.
As this is a “Get” example, it seems only logical to show what the output actually looks like (execution from PowerShell):
Please refer to the example directly below for a version of the PowerShell which works in the Preview Release of SMA as well (though, the output lacks the specified formatting above):
Note The main differences include: Removal of $CustomPropertyValue as a declared array; Removal of anything outside $CustomPropertyValue being assigned the object results from the execution of Get-VMMCustomPropertyValue
Here is a look at the output as seen from SMA (differences are immediately apparent):
As promised, each of the above examples have been included in a TechNet Gallery Contribution.
The download includes the following (5) PS1 files which represent the (5) examples from the “Example SMA Runbook Rundown!” section above:
And the following (1) PS1 file which represents a collection of all the PowerShell snippets from the “Calling the Runbooks” section above:
Note Each of the sections in this collection of PowerShell snippets has been individually commented out (including the variables at the top). To leverage any of the snippets, simply modify the comment tags.
Download the SMA Example - VMM Custom Property Management (w/PS v3 Workflow) from TechNet Gallery here:
That’s it! I hope this VMM Custom Property Management Examples post provided you with a few more useful gadgets in your SMA Runbook / PowerShell v3 Workflow utility belt!
Oh, and if you want more examples for SMA and PowerShell v3 Workflow, be sure to check out this list (to be updated as more examples are provided):
And for more information, tips/tricks, and example solutions for SMA, be sure to watch for future blog posts in the Automation Track!