Web Service URLs
Web Service URL (no change for 2016):
http://sco01:81/orchestrator2012/orchestrator.svc/
Web Console URL:
http://sco01:82/
Get runbooks:
http://server01.contoso.com:81/Orchestrator2012/Orchestrator.svc/Runbooks
Access Orchestrator Runbooks via Web Service
Get a Runbook
PowerShell
$secpasswd = ConvertTo-SecureString "Password01!" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential("contoso\Administrator", $secpasswd)
$OrchURI = "http://SCO01:81/Orchestrator2012/Orchestrator.svc/Runbooks?`$filter=Name eq 'Test'"
$ResponseObject = invoke-webrequest -Uri $OrchURI -method Get -Credential $mycreds
$ResponseObject.Content
Postman
http://SCO01:81/Orchestrator2012/Orchestrator.svc/Runbooks?$filter=Name eq 'Test'"
Start a Runbook
PowerShell
$OrchURI = "http://SCO01:81/Orchestrator2012/Orchestrator.svc/Jobs/"
$POSTBody = @"
<?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">87be7221-2a15-4e41-91f6-35f4d3006d53</d:RunbookId>
<d:Parameters></d:Parameters>
</m:properties>
</content>
</entry>
"@
$ResponseObject = invoke-webrequest -Uri $OrchURI -method POST -Credential $mycreds -Body $POSTBody -ContentType "application/atom+xml"
$ResponseObject.Content
Postman
http://SCO01:81/Orchestrator2012/Orchestrator.svc/Jobs
Confirm the runbook enters running status:
Reference
Accessing System Center 2012 Orchestrator Using the Web Service
Starting Runbooks and Stopping Jobs Using the System Center 2012 Orchestrator Web Service
Calling Orchestrator Runbooks (& retrieving output) via REST
The Job status loop can be improved by using the stopwatch to limit the amount of time for the job to start instead of a simple counter. Also you can use Invoke-RestMethod instead of Invoke-WebRequest so that it automatically parses the XML returned.
$WaitSec = 10
$MaxWait = New-TimeSpan -Minutes 4
$ResponseObject = Invoke-RestMethod -Uri (“http://{0}:81/Orchestrator2012/Orchestrator.svc/Jobs/” -f $OrchServer) -method POST -Body $POSTBody -ContentType “application/atom+xml” -UseDefaultCredentials
For ($ElapsedTime = [System.Diagnostics.Stopwatch]::StartNew();($ResponseObject.entry.content.properties.Status -eq ‘Pending’) -and ($ElapsedTime.Elapsed -le $MaxWait) ;Start-Sleep -Seconds $WaitSec ){
Write-Host (“Elapsed time: {0} – Job Still pending, waiting $WaitSec seconds” -f $ElapsedTime.Elapsed) -ForegroundColor Cyan
$ResponseObject = Invoke-RestMethod -Uri $ResponseObject.entry.id -UseDefaultCredentials
}
$ElapsedTime.Stop()
If ($ResponseObject.entry.content.properties.Status -eq ‘Running’) {
Write-Host “Successful Job start. Status: $($ResponseObject.entry.content.properties.Status)” -ForegroundColor Green
} else {
Write-Host “Job status is not running. Current Status: $($ResponseObject.entry.content.properties.Status)” -ForegroundColor Yellow
}