Here is an example to try out :
# variables
$username = "bao"
$password = "guess"
$wfaserver = "123.1.1.1"
$uri = "http://$wfaserver/wfa-ws/WorkflowService_rpc?wsdl"
# note : if the ssl certificate is not installed used http, if ssl is installed https will work
$parameters = @()
#$VerbosePreference = "continue"
# create credentials
Write-Verbose "Creating credentials"
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,$password)
# fire up the webservice
Write-Verbose "Connect to webservice $uri"
[System.Net.ServicePointManager]::Expect100Continue = $false
$wfa = New-WebServiceProxy -Uri $uri -Credential $cred
# get list of workflows
Write-Verbose "Get the workflows"
$workflows = $wfa.getAllWorkflows()
# list them up
Write-Output "Pick a workflow"
Write-Output "==============="
$workflowIds = @() # build a valid workflowid array
foreach($workflow in $workflows){
$workflowIds += $workflow.id
Write-Output "$($workflow.id) : $($workflow.name)"
}
# prompt for workflow id with error checking
do{
$workflowId = read-host "Enter a valid Workflow-id you want to start"
}
while($workflowIds -notcontains $workflowId)
# get chosen workflow
Write-Verbose "Get workflow $workflowid"
$workflow = $workflows | where{$_.id -eq $workflowId}
# get user input
Write-Verbose "Extract userput fields"
$userinputFields = $workflow | select -ExpandProperty userinput
foreach($field in $userinputFields){
$input = ""
$validationString = ""
Do{
Write-Output "-----------------------------------"
# description
if($field.description){
Write-Output "Description : $($field.description)"
}
# validation presentation
if($field.value){
$validationString = $field.value
# visualize Enum with "|"
if($field.type -eq "Enum"){
$validationString = "[" + ($field.value -join "|") + "]"
}
Write-Output "Validation : $validationString"
}
# get default value if any
if($field.defaultValue){
$defaultValue = " [$($field.defaultValue)]"
}else{
$defaultValue = ""
}
# read the input
$input = read-host "$($field.name)$defaultValue"
# set the default value
if((-not $input) -and $field.defaultValue){
Write-Verbose "No input given : defaulting the value to $($field.defaultValue)"
$input = $field.defaultValue
}
# validate the input
# default = true
$validation = $true
# only validation if value is given
if($field.value){
# number - scan the range
if($field.type -eq "Number"){
$range = $validationString -split "-"
$input = [Int32]$input
$lowest = [Int32]$range[0].Trim()
$highest = [Int32]$range[1].Trim()
$validation = (($input -ge $lowest) -and ($input -le $highest))
Write-Verbose "Validated number $input as $validation between $lowest and $highest"
}
# enumeration - check the array
if($field.type -eq "Enum"){
$validation = $field.value -contains $input
Write-Verbose "Validated enumeration $input as $validation in array {$($field.value -join ",")}"
}
# string - check the regex
if($field.type -eq "String"){
# we change the regex a bit (^ & $) to get it working
$validation = $input -match "^$validationString$"
Write-Verbose "Validated string $input as $validation against regex /$validationString/"
}
}
}while(-not $validation)
Write-Verbose "Adding parameters : $($field.name)=$input"
$parameters += "$($field.name)=$input"
}
# lauch the workflow
Write-Verbose "Launching the workflow $($workflow.id) with parameters $parameters"
$jobid = $wfa.executeWorkflow($workflow.id,$parameters)
# monitor job status
do{
$status = $wfa.getJobStatus($jobid)
Write-Output "Workflow status : $($status.jobStatus1)..."
Write-Verbose "Sleeping 2 seconds"
Start-Sleep 2
}
while($status.jobStatus1 -ne "COMPLETED")
Write-Verbose "Job completed"
write-output "returning parameters through the job status"
foreach($param in $status.returnParameter){
write-output "$($param.name) = $($param.value)"
}
write-output "returning parameters through webservice"
foreach($param in $workflow.returnParameters){
$returnedParameter = $wfa.getReturnParameters($jobid,$param.name)
write-output "$($returnedParameter[0].name) = $($returnedParameter[0].value)"
}
$stop = Read-Host 'job finished... press enter to stop'