Activity
Applies To: System Center 2012 - Orchestrator, System Center 2012 R2 Orchestrator, System Center 2012 SP1 - Orchestrator
The Activity entity represents an activity in an Orchestrator runbook. The Activities collection includes all of the activities in all the runbooks in the local Orchestrator environment.
Properties
The following table lists the properties of the Activity entity.
Name | Type | Key | Description |
---|---|---|---|
CreatedBy |
String |
No |
Empty. Not used. |
CreationTime |
DateTime |
No |
Date and time that the activity was created. |
Enabled |
Boolean |
No |
Specifies whether the activity is enabled. |
Id |
GUID |
Yes |
Unique identifier of the activity. |
LastModifiedBy |
String |
No |
Empty. Not used. |
LastModifiedTime |
DataTime |
No |
Date and time that the activity was last modified. |
Name |
String |
No |
The name of the activity. |
PositionX |
Integer |
No |
The horizontal position of the activity in the runbook. |
PositionY |
Integer |
No |
The vertical position of the activity in the runbook. |
RunbookId |
GUID |
No |
Unique identifier of the runbook that the activity is in. |
TypeName |
String |
No |
The name of the activity’s type. |
Relationships
The following table lists the entities that share a relationship with the Activity entity and the key property in each entity used to define the relationship.
Collection | Entity | Relationship | Related Entity Property | Activity Entity Property |
---|---|---|---|---|
Instances |
ActivityInstance |
Child |
ActivityId |
Id |
Runbook |
Runbook |
Parent |
Id |
RunbookId |
Code Samples
Getting Activities using C#
The following code retrieves the activities from a particular runbook 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 SingleRunbook
{
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");
// Retrieve the runbook
Runbook runbook = context.Runbooks.Where(rbk => rbk.Id == runbookId).FirstOrDefault();
// Retrieve activities
var runbookActivities = context.Activities.Where(runbookActivity => runbookActivity.RunbookId == runbookId);
// Output runbook properties to console
Console.WriteLine("Id: {0}", runbook.Id);
Console.WriteLine("Name: {0}", runbook.Name);
Console.WriteLine("IsMonitor: {0}", runbook.IsMonitor);
Console.WriteLine("Activities:");
// Output properties for each parameter to console
foreach (var activity in runbookActivities)
{
Console.WriteLine("\t{0} {1} - {2}", activity.Id, activity.TypeName, activity.Name);
}
}
}
}
Getting Jobs using Windows PowerShell
The following code retrieves the activities from a particular runbook 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
$url = -join ("http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/","Runbooks(guid'",$runbookId.ToString(),"')/Activities")
$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()
# Output properties of each activity
foreach ($activity in $output.feed.entry)
{
Write-Host "Name: " $activity.content.properties.Name
Write-Host "TypeName: " $activity.content.properties.TypeName
}
See Also
Concepts
Programming Using the Orchestrator Web Service
OData Queries Using the Orchestrator Web Service
Authentication and Authorization