Listing your Orchestrator Runbooks using PowerShell

As part of a bigger post on Runbooks, I needed to find a way of listing the names of my Orchestrator Runbooks using PowerShell. This script will output the name and the ID of each Runbook.

#############################################################################
#
# Get-Runbooks.ps1
# Date: 28/10/2014
# Version: 1.0
# Website: www.culham.net
#
# Happy to hear of any bugs, feedback, ideas for improvement.
# Contact me at the above website.
#
# Remember to change $orchestratorServer to the name of your own
# Orchestrator Server
#
##############################################################################

# The Name of your Orchestrator Runbook Server
$orchestratorServer = “ORCHESTRATORSERVERNAME”

# The URL to your Orchestrator Runbook Server
$baseurl = “http://”+$orchestratorServer+”:81/Orchestrator2012/Orchestrator.svc/”

# Base URL for Jobs collection
$url = “$baseurl/Runbooks”

$request = [System.Net.HttpWebRequest]::Create($url)

# Set the credentials to use the default ones (the ones you are logged on with right now) or prompt for credentials.
# First line uses the currently logged on credentials, second line will prompt you for alternate 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 Http Web Response to String
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
[xml]$output = $output
$reader.Close()

# Array to hold the results
$OutData =@()

# Output properties of each job in page to our array
foreach ($runbook in $output.feed.entry)
{
$RunbookDetail = New-Object PSObject
$RunbookDetail | Add-Member -Name “Runbook Name” -MemberType NoteProperty -Value $runbook.content.properties.Name
$RunbookDetail | Add-Member -Name “Runbook ID” -MemberType NoteProperty -Value $runbook.content.properties.ID.InnerText
$OutData += $RunbookDetail
}

# Display the Results
$OutData | Sort-Object “Runbook Name” | ft -autosize
Write-Host “Total Number of Jobs is” $OutData.Count

 

This will give you output like this:

Runbook List

 

 

 

Download the script here: Get-Runbooks

Enjoy!

 
Comments

Hi,

I’ve just made a few minor changes and parameterised some bits.. updated script here:

#############################################################################
#
# Get-Runbooks.ps1
# Date: 28/10/2014
# Version: 1.0
# Website: http://www.culham.net
#
# Happy to hear of any bugs, feedback, ideas for improvement.
# Contact me at the above website.
#
# Remember to change $OrchestratorServer to the name of your own
# Orchestrator Server
#
# Version 1.1 – added parameters – David Wallis blog.wallis2000.co.uk
##############################################################################

function Get-Runbooks {
param(
[Parameter(Position=0, Mandatory=$true)]
[System.String]$OrchestratorServer,

[Parameter(Position=1, Mandatory=$False)]
[string]$OrchestratorProtocol=”http”,

[Parameter(Position=2, Mandatory=$false)]
[System.String]$OrchestratorPort=”81″,

[Parameter(Position=3, Mandatory=$false)]
[bool]$UseDefaultCreds=$true
)

# The URL to your Orchestrator Runbook Server
$baseurl = “$($OrchestratorProtocol)://$($OrchestratorServer):$($OrchestratorPort)/Orchestrator2012/Orchestrator.svc/”

# Base URL for Jobs collection
$url = “$baseurl/Runbooks”
$request = [System.Net.HttpWebRequest]::Create($url)

# Set the credentials to use the default ones (the ones you are logged on with right now) or prompt for credentials.
if ($UseDefaultCreds) {
$request.UseDefaultCredentials = $true
}Else{
$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 Http Web Response to String
$reader = [IO.StreamReader] $response.GetResponseStream()
$output = $reader.ReadToEnd()
[xml]$output = $output
$reader.Close()

# Array to hold the results
$OutData =@()

# Output properties of each job in page to our array
foreach ($runbook in $output.feed.entry)
{
$RunbookDetail = New-Object PSObject
$RunbookDetail | Add-Member -Name “Name” -MemberType NoteProperty -Value $runbook.content.properties.Name
$RunbookDetail | Add-Member -Name “ID” -MemberType NoteProperty -Value $runbook.content.properties.ID.InnerText
$OutData += $RunbookDetail
}

$OutData #| Sort-Object “Runbook Name” | ft -autosize
#Write-Host “Total Number of Jobs is” $OutData.Count
}

# Call Function

Get-Runbooks -OrchestratorServer SERVERNAME.YOURDOMAIN.COM |Select Name

Thanks for contributing David, I look forward to trying your code out.

Hi

Thank you so much for this, I was dealing with an analyst who kept telling me to use a particular runbook but each time we tried to use it we got a runbook does not exist error. I was getting frustrated so I asked my mate google how interrogate a list of runbooks and came across your blog. Now I was able to send the analyst a list of runbooks that I was able to access and lo and behodl the one they were telling me to use was not on the list.

Cheers mate!

You are most welcome. Glad it helped 🙂

Trackbacks for this post

Leave a Reply