Scripts/Start-BPAWorkflow.ps1
function Start-BPAWorkflow { <# .SYNOPSIS Starts AutoMate BPA workflows. .DESCRIPTION Start-BPAWorkflow starts workflows. .PARAMETER InputObject The workflows to start. .INPUTS Workflows can be supplied on the pipeline to this function. .EXAMPLE # Starts workflow "My Workflow" Get-BPAWorkflow "My Workflow" | Start-BPAWorkflow .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 08/24/2016 Date Modified : 02/27/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding()] [OutputType([System.Object[]])] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] $InputObject ) PROCESS { foreach ($obj in $InputObject) { if ($obj.TypeName -eq "Workflow") { Write-Verbose "Running workflow $($obj.Name)." $instanceID = Invoke-BPARestMethod -Resource "workflows/$($obj.ID)/run" -RestMethod Post -BPAServer $obj.BPAServer Start-Sleep -Seconds 1 # The instance can't be retrieved right away, have to pause briefly Invoke-BPARestMethod -Resource ('instances/list?filter_sets="ID","=","\"' + $instanceID + '\""') -RestMethod Get -BPAServer $obj.BPAServer } else { if ($_) { $message = "Unsupported input type '$($obj.TypeName)' encountered!" } else { $message = "Unsupported input type '$($obj.Type)' encountered!" } Write-Error -Message $message -TargetObject $obj } } } } |