Press "Enter" to skip to content

Calling vRO Workflow via Powershell

Hey Hey,

This is something I did a while ago and been meaning to post for ages, but since I now have free time again for the short period im trying to get some content out there which hopefully helps others.

Ive been heavily evolved in vCAC, APPD and vCO (Old names) which are now vRA, vRO and vRA Application Services to deploy complex platform automation. Due to the zero integration Application Services has with vCO and to address some short comings of Application services we needed a way to call vCO workflows and allow for the sending of inputs and receiving back all outputs.
This is achieved with a script, My Colleague Chris Slater had made one for Linux based virtual machines and has previous blogged on that Located HERE which basically does the same thing.

The script I will be showing you today is a powershell script so windows machines could also benefit and does a couple additions such as creating variables from an output if it doesn’t exist.

In the script shown bellow you will notice there is a prefix that is set. while this is aligned to the configure and teardown activities in Application Services the prefix purely decides what gets passed to the vRO workflow. The prefix is also removed when sending the variables to vRO.

Download have a play and any questions hit me up


add-type @"

using System.Net;

using System.Security.Cryptography.X509Certificates;

public class TrustAllCertsPolicy : ICertificatePolicy {

public bool CheckValidationResult(

ServicePoint srvPoint, X509Certificate certificate,

WebRequest request, int certificateProblem) {

return true;



[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy


Write-output "Configuring user Authentication"
$auth = $vCOUserUPN + ':' + $vCOPass
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$EncodedPassword = [System.Convert]::ToBase64String($Encoded)
$headers = @{"Authorization"="Basic $($EncodedPassword)";}
Write-output "User authentication Completed"

Write-output "Configuring Template to use"
$template ='<parameter type="string" name="replaceme" scope="local"><string>propertyreplace</string></parameter>'

if ($PREFIX -eq "CONF_") {
$url = "https://"+$vCOFQDN+":8281/vco/api/workflows/$CONF_workflowid/executions/"
$geturl = "https://"+$vCOFQDN+":8281/vco/api/workflows/$CONF_workflowid/"
elseif ( $PREFIX -eq "TEAR_"){
$url = "https://"+$vCOFQDN+":8281/vco/api/workflows/$TEAR_workflowid/executions"
$geturl = "https://"+$vCOFQDN+":8281/vco/api/workflows/$TEAR_workflowid/"

write-output "URL is to be used is : $url"

$body = "<execution-context xmlns=''><parameters>"
Write-output "Getting required inputs for workflow"
$res = Invoke-restmethod -uri $geturl -Headers $headers -contenttype "application/json" -Method Get
write-output "Response is : $res"
$inputs = $res."input-parameters"
write-output "vCO inputs available are" $inputs
$var = get-variable

Write-output "Using PREFIX to determine what inputs are going to be sent to vCO"
foreach ($i in $var) {
$found = $ -match $PREFIX
$name = $
$value = $i.value
##write-host $name and $value
if ($found) {
$newVar = $name -replace $PREFIX
foreach ($v in $inputs) {
if ($ -eq $newVar) {
write-output "using: $newVar"
$temptemplate = $template
$temptemplate = $temptemplate -replace "replaceme","$newVar"
$temptemplate = $temptemplate -replace "propertyreplace","$value"
$body += $temptemplate



$body += "</parameters></execution-context>"

write-output "body to be used is: "$body

Write-output "Sending POST request to workflow"
$return = Invoke-WebRequest -uri $url -Headers $headers -Body $body -contenttype "application/xml" -Method Post

Write-output $return.statusdescription

$workingID = $return.headers.location
do {
$checking = Invoke-restMethod -uri $workingID -Headers $headers -contenttype "application/xml" -Method Get
$state = $checking.state
write-host "State is: " $state
start-sleep -s 5
while($state -eq "running")

$output = $checking."output-parameters"

If ($state -eq "completed"){
Foreach ($o in $output){
$tempfound = "no"
$tempname = $
$tempvar = $o.value
$tempvalue = $tempvar.string.value
Foreach ( $i in $var){
$found = $ -match $tempname
if ($found){
set-variable $ $tempvalue
$tempfound = "found"
if ($tempfound -ne "found") {
new-variable $ $o.value


If ($state -eq "failed"){
$error = $checking."content-exception"
$failedcomponent = $checking."current-item-display-name"

Write-output "Work flow failed with the following error: $error"
Write-output "Workflow failed on component: $failedcomponent"
exit 1


One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM BOT Question * Time limit is exhausted. Please reload CAPTCHA.