Runbook Instance Parameter
Applies To: System Center 2012 - Orchestrator, System Center 2012 R2 Orchestrator, System Center 2012 SP1 - Orchestrator
The RunbookInstanceParameter entity represents values from the parameters of running Orchestrator runbooks. The RunbookInstanceParameters collection includes all of the runbook instance parameters from all runbooks in the local Orchestrator environment. You can use the Runbook collection on the RunbookInstanceParameter to retrieve the runbook instance parameters for a particular runbook.
A runbook can have input parameters that are defined in an Initialize Data activity. These are values that the runbook requires to run properly. It can also have output parameters that are defined on the Returned Data tab of the runbook’s properties. These values can be set with a Return Data activity. The type of parameter is specified with the Direction property.
Properties
The following table lists the properties of the RunbookInstanceParameter entity.
Name | Type | Key | Description |
---|---|---|---|
Direction |
String |
No |
The direction of the parameter. A value of In specifies an input parameter for the runbook. A value of out |
GroupId |
Integer |
No |
|
Id |
GUID |
Yes |
Unique identifier of the runbook. |
Name |
String |
No |
Name of the runbook parameter. |
RunbookInstanceID |
GUID |
No |
Unique identifier of the runbook instance. |
RunbookParameterID |
GUID |
No |
Unique identifier of the runbook parameter. |
Relationships
The following table lists the entities that share a relationship with the RunbookInstanceParameter entity and the key property in each entity used to define the relationship.
Collection | Entity | Relationship | Related Entity Property | RunbookInstanceParameter Property |
---|---|---|---|---|
RunbookInstance |
RunbookInstance |
Parent |
Id |
RunbookInstanceId |
RunbookParameter |
RunbookParameter |
Parent |
Id |
RunbookParameterId |
Code Samples
Getting Runbook Instance Parameters using C#
The following code retrieves the parameter values from a particular runbook instance using C#. This example uses a service reference named SCOService and uses the credentials of the current user context. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Programming in Visual Studio With the Orchestrator Web Service and Authentication and Authorization.
namespace CodeSample.Microsoft.SystemCenter.Orchestration.WebService
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data.Services.Client;
using SCO.SCOService;
public class RunbookInstanceParameters
{
public static void Main()
{
Guid runbookId = new Guid("00000000-0000-0000-0000-000000000000");
// Path to Orchestrator web service
string serviceRoot = "http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc";
// Create Orchestrator context
SCOService.OrchestratorContext context = new SCOData.OrchestratorContext(new Uri(serviceRoot));
// Set credentials to default or to a specific user.
context.Credentials = System.Net.CredentialCache.DefaultCredentials;
//context.Credentials = new System.Net.NetworkCredential("user", "pwd", "domain");
// Setup Data Services query
DataServiceQueryContinuation<RunbookInstance> nextRunbookInstanceLink = null;
try
{
// Setup the query to retrieve the runbook instance. In this case, it’s the last instance to have run.
RunbookInstance runbookInstance = (from rbkInstance in context.RunbookInstances
where rbkInstance.RunbookId == runbookId
orderby rbkInstance.CreationTime descending
select rbkInstance).FirstOrDefault();
// Query for the parameters of the runbook instance
IEnumerable<RunbookInstanceParameter> runbookInstanceParameters = context.RunbookInstanceParameters.Where(rip => rip.RunbookInstanceId == runbookInstance.Id);
// Output the properties of parameter to the console
foreach (RunbookInstanceParameter runbookInstanceParameter in runbookInstanceParameters)
{
Console.WriteLine("Direction: {0}, Name: {1}, Value: {2}", runbookInstanceParameter.Direction, runbookInstanceParameter.Name, runbookInstanceParameter.Value);
}
}
catch (DataServiceQueryException ex)
{
throw new ApplicationException("An error occurred during query execution.", ex);
}
}
}
}
Getting Runbook Instance Parameters using Windows PowerShell
The following code retrieves the parameter values from a particular runbook instance using Windows PowerShell. The example uses the credentials of the current user context. You can uncomment the line that specifies alternate credentials if the current user does not have appropriate permissions to the runbook being started. For more information see Authentication and Authorization.
# Details of the runbook we want to get
$runbookId = "00000000-0000-0000-0000-000000000000"
# Create the request object for the runbook instance
$runbookInstanceUrl = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","Runbooks(guid'",$runbookId.ToString(),"')/Instances")
$queryOptions = "?`$orderby=CreationTime desc&`$top=1"
$url = -join($runbookInstanceUrl,$queryOptions)
$request = [System.Net.HttpWebRequest]::Create($url)
# Set the credentials to default or prompt for credentials
$request.UseDefaultCredentials = $true
# $request.Credentials = Get-Credential
# Build the request header
$request.Method = "GET"
$request.UserAgent = "Microsoft ADO.NET Data Services"
# Get the response from the request
[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()
# Write the HttpWebResponse to String
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
[xml]$output = $output
$reader.Close()
# Get the runbook instance Id which we need for the next request
$runbookInstanceId = $output.feed.entry.content.properties.id.innertext
# Create the request object for the parameters
$parameterUrl = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","RunbookInstances(guid'",$runbookInstanceId.ToString(),"')/Parameters")
$request = [System.Net.HttpWebRequest]::Create($parameterUrl)
# Set the credentials to default or prompt for credentials
$request.UseDefaultCredentials = $true
# $request.Credentials = Get-Credential
# Build the request header
$request.Method = "GET"
$request.UserAgent = "Microsoft ADO.NET Data Services"
# Get the response from the request
[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()
# Write the HttpWebResponse to String
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
[xml]$output = $output
$reader.Close()
# Output properties of each parameter
foreach ($parameter in $output.feed.entry)
{
Write-Host "Direction: " $parameter.content.properties.Direction
Write-Host "Name: " $parameter.content.properties.Name
Write-Host "Value: " $parameter.content.properties.Value
}
See Also
Concepts
Programming Using the Orchestrator Web Service
OData Queries Using the Orchestrator Web Service