Saturday, June 2, 2012

SCOrch – Powershell to start Runbook – Part 1

I have seen a few examples of ways to start a runbook with C and VB.  However, I haven’t come across any ways of using Powershell to start a runbook successfully.

This will be the first post of a series of different ways to interact w/ the web service through Powershell.  I’ll also post how to start w/ parameters, stop a runbook, get all running/pending runbooks, etc….

Here’s the short of it.  I Haven’t built any logic, parameters, or error handling into it yet….just wanted to get the POST to work with Orchestrator’s web service.

You would need to update the credentials, url for the web service pointed to the Jobs collection, and the RunbookID in the request body (highlighted below).

##############################################################################
$creds = Get-Credential("domain\username")
$Output = $null
$Success = $null
$url = "http://scorch.domain:81/Orchestrator2012/Orchestrator.svc/Jobs/"
$request = [System.Net.HttpWebRequest]::Create($url)
$request.Credentials = $creds
$request.Timeout = 36000
$request.Accept = "application/atom+xml,application/xml"
$request.Headers.Add("Accept-Charset", "UTF-8")
$request.ContentType = "application/atom+xml"
$request.Method = "POST"

#Request w/o Parameters
$requestBody = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<m:properties>
<d:RunbookId type="Edm.Guid">RunbookGUID</d:RunbookId>
</m:properties>
</content>
</entry>
'

$requeststream=new-object System.IO.StreamWriter $request.GetRequestStream()
$requeststream.Write($requestBody)
$requeststream.Flush()
$requeststream.Close()
$response=$request.GetResponse()
$requestStream=$response.GetResponseStream()
$readStream=new-object System.IO.StreamReader $requestStream
$Output=$readStream.ReadToEnd()
$readStream.Close()
$response.Close()

$Output
##############################################################################

1 comment:

  1. Spot on with this write-up, I actually assume this website wants far more consideration. I’ll in all probability be again to read much more, thanks for that info. free online casino slots

    ReplyDelete