SMA: Calling an Orchestrator Runbook from Service Management Automation

Hi All,

Today, a small blog about calling an Orchestrator Runbook from a SMA Runbook. This topic has been already discussed by Tiander here: http://blogs.technet.com/b/privatecloud/archive/2013/11/01/calling-an-orchestrator-runbook-from-sma-part-1.aspx
The problem with the proposed approach is that for each Orchestrator RB Inputs, you need to add several lines at different places in the SMA Runbook. That’s directly introduce a risk of error/typo, the workflow is less readable and more difficult to maintain.

After a chat with Charles Joy from Microsoft, we improved the SMA RB by using a new hashtable to contain the Orchestrator Variable Names and Values. Like this, if you need to add or remove an Orchestrator parameter, you just need to add/remove an entry in this hashtable.

$RBParamsAndVals = @{
    "Virtual Machine Name" = "MyVM001"
    "Checkpoint Name" = "Before Software Update"
    "Checkpoint Description" = "Requested by Christopher From SMA via SCORCH"
}
 

Now that’s the inputs have been defined, we’ll dynamically populate the Variable values in a new hashtable with the parameter GUID as Key.

What do you think? Easy to use, re-use and maintain J

The full SMA workflow is available below:

workflow Invoke-OrchestratorRunbook
{
#Connection to SCORCH Runbook
$SCOserverName = "SCORCH001.vnextlab.be"
$PSUserCred = Get-AutomationPSCredential -Name 'vnextlab\sa_scorch'
$MyRunbookPath = "\SC2012 Solutions\1.0 Cloud Management\1.1.0 VM Checkpoint Management\Cloud Management | VM Checkpoint Management | 1.1.1 Create Checkpoint"  

#Provide the Initialize Data activity parameters:
$RBParamsAndVals = @{
    "Virtual Machine Name" = "VEEAM001"
    "Checkpoint Name" = "Before Software Update"
    "Checkpoint Description" = "Requested by Christopher From SMA via SCORCH"
} 

# Get the url for the Orchestrator service
$url = Get-OrchestratorServiceUrl -Server $SCOserverName 

# Get a Runbook by Path and Name
$Runbook = Get-OrchestratorRunbook -serviceurl $url -credentials $PSUserCred -RunbookPath $MyRunbookPath  

#Correlate the Initialize Data parameters with our values
[hashtable] $paramsTable = @{}
foreach ($key in $RBParamsAndVals.Keys)
    {
     foreach ($param in $runbook.Parameters)
           {
            if($Param.Name -eq $Key)
                {
                 [hashtable]$paramsTable.Add($param.Id,$RBParamsAndVals[$key])
                }
            }
    } 

# Start the runbook
$job = Start-OrchestratorRunbook -runbook $runbook -parameters $paramsTable -credentials $PSUserCred
# Show the Runbook job information
$job
}
Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+Email this to someoneShare on TumblrPin on PinterestDigg thisShare on RedditFlattr the authorBuffer this pageShare on StumbleUpon

About Christopher Keyaert

Christopher Keyaert is a Consultant, focused on helping partners to leverage the System Center and Microsoft Azure cloud platform. He is also a Microsoft Most Valuable Professional (MVP) for Cloud and Data Center Management and a Microsoft Certified Trainer (MCT).
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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