Scripts/Resume-BPAInstance.ps1
function Resume-BPAInstance { <# .SYNOPSIS Resumes AutoMate BPA workflow and task instances. .DESCRIPTION Resume-BPAInstance resumes paused workflow and task instances. .PARAMETER InputObject The instances to resumes. .INPUTS Instances can be supplied on the pipeline to this function. .EXAMPLE # Resumes all currently paused instances Get-BPAInstance -Status Paused | Resume-BPAInstance .EXAMPLE # Resumes all currently paused instances of workflow "My Workflow" Get-BPAWorkflow "My Workflow" | Get-BPAInstance -Status Paused | Resume-BPAInstance .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 09/14/2016 Date Modified : 02/27/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(DefaultParameterSetName = "All")] [OutputType([System.Object[]])] param( [Parameter(ValueFromPipeline = $true, ParameterSetName = "ByPipeline")] [ValidateNotNullOrEmpty()] $InputObject ) PROCESS { foreach ($obj in $InputObject) { switch ($obj.TypeName) { "Instance" { switch ($obj.Status -as [BPAInstanceStatus]) { "Paused" { switch ($obj.ConstructType -as [BPAConstructType]) { "Workflow" { Invoke-BPARestMethod -Resource "workflows/$($obj.ConstructID)/running_instances/$($obj.ID)/resume" -RestMethod Post -BPAServer $obj.BPAServer | Out-Null Start-Sleep 1 # The instance can't be retrieved right away, have to pause briefly Invoke-BPARestMethod -Resource ('instances/list?filter_sets="ID","=","\"' + $obj.ID + '\""') -RestMethod Get -BPAServer $obj.BPAServer } "Task" { Invoke-BPARestMethod -Resource "tasks/$($obj.ConstructID)/running_instances/$($obj.ID)/resume" -RestMethod Post -BPAServer $obj.BPAServer | Out-Null Start-Sleep 1 # The instance can't be retrieved right away, have to pause briefly Invoke-BPARestMethod -Resource ('instances/list?filter_sets="ID","=","\"' + $obj.ID + '\""') -RestMethod Get -BPAServer $obj.BPAServer } default { if ($_) { $message = "Unsupported construct type '$_' encountered! Workflow: $($obj.Name)" } else { $message = "Unsupported construct type '$($obj.Type)' encountered! Workflow: $($obj.Name)" } Write-Error -Message $message -TargetObject $obj } } } default { Write-Error -Message "Instance $($obj.ID) is not suspended! Status: $_" -TargetObject $obj } } } default { Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj } } } } } |