Fun with the Orchestrator 2012 Beta,the Web Service and PowerShell

Published Feb 15 2019 07:22 AM 76 Views
First published on TECHNET on Jun 17, 2011

The Orchestrator 2012 Beta is barely “out of the oven” and I have some fun PowerShell stuff for you to play with using the new REST-based web service. Working with web services from PowerShell is rather new to me, but I was surprised how easy it was to create a few functions that let me browse around the contents of the data in Orchestrator using the web service. Get the PowerShell script for all of this here .

First of all, I created a function to do the actual connection to the web service and querying it. Thanks to another smart person for coming up with this part ( see my previous post where I talked about this ). This function is called Query-RestService , This is a generic function that allows me to call virtually any REST-based web service. On top of that, I have another function called Query-SCOService. The Query-SCOService function simply formats the URI properly for the SCO web service (which you could do yourself with the Query-RestService function). If I call this function and don’t provide a query, I get the same thing I’d get if I typed the default web service URL into a browser:

Web Service Response

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<service xml:base="http://sco12-rh1:81/Orchestrator.svc/" xmlns:atom="" xmlns:app="" xmlns="">
<collection href="Folders">
<collection href="Runbooks">
<collection href="RunbookParameters">
<collection href="Activities">
<collection href="Jobs">
<collection href="RunbookInstances">
<collection href="RunbookInstanceParameters">
<collection href="ActivityInstances">
<collection href="ActivityInstanceData">
<collection href="RunbookServers">
<collection href="RunbookDiagrams">
<collection href="Statistics">

The really good stuff comes with the ConvertTo-SCOObject function. This function takes the XML output from the web service query and converts it into custom PSObjects that look like this:

Sample "Job" Object

Object Type      : Job
Id               : 2976c7c0-860c-48d0-b102-257a59ae4493
RunbookId        : e042d1f6-040a-48a7-a2b5-b850d1145c9c
Parameters       : <Data/>
RunbookServers   :
RunbookServerId  : 3af5371d-3ba2-49f5-83ad-0264d2427481
ParentId         : e950b167-cf82-434f-a726-160d05ab15b8
ParentIsWaiting  : false
Status           : Completed
CreatedBy        : S-1-5-500
CreationTime     : 2011-06-11T15:21:44.653
LastModifiedBy   : S-1-5-500
LastModifiedTime : 2011-06-11T15:21:46.49
Job              : Jobs(guid'2976c7c0-860c-48d0-b102-257a59ae4493')
Runbook          : Jobs(guid'2976c7c0-860c-48d0-b102-257a59ae4493')/Runbook
Instances        : Jobs(guid'2976c7c0-860c-48d0-b102-257a59ae4493')/Instances
RunbookServer    : Jobs(guid'2976c7c0-860c-48d0-b102-257a59ae4493')/RunbookServer
Statistics       : Jobs(guid'2976c7c0-860c-48d0-b102-257a59ae4493')/Statistics

I can create one object or an array of these objects easily, just by doing the following:

(1)   Create an object containing the XML output from the web service query in Atom put feed format:

$xmlfeed = Query-Rest -scoserver "sco12-rh1" -credentials $cred -query "Jobs?$filter=RunbookId%20eq%20guid'9296a3c2-29b1-4000-a155-e8e3adc855e9'"

(2)   Pass this xml into the ConvertTo-SCOObject function

ConvertTo-SCOObject -XmlFeed $xmlfeed

The resulting output is one or more objects that can then be used for further querying. For example, if I want to get a list of all Instances of a job that do not have a status of “completed” and show only their IDs, I could do this:

Query-SCOService -scoserver "sco12-rh1” -credentials $cred -query (ConvertTo-SCOObject -XmlFeed $xmlfeed | ? {$_.Status -ne "Completed"}).Instances | Select ID

Do you see how I am utilizing the properties as extensions to the base URI? Cool, huh?

I whipped this whole thing up in a couple of hours. I encourage you to play around with it and try new things. When we ship Orchestrator 2012, we’ll have an official, shipping PowerShell interface that’s built on top of the web service, and it will definitely be much better than this simple script, but between now and then this is something to get you thinking about how useful PowerShell and the new web service are together.

Get the PowerShell script for all of this here


Version history
Last update:
‎Mar 11 2019 08:48 AM
Updated by: