Scripts/Resume-BPAWorkflow.ps1

function Resume-BPAWorkflow {
    <#
        .SYNOPSIS
            Resumes a failed AutoMate BPA workflow.
 
        .DESCRIPTION
            Resume-BPAWorkflow resumse paused workflow and task instances.
 
        .PARAMETER InputObject
            The workflow(s) to resumse.
 
        .INPUTS
            Workflows can be supplied on the pipeline to this function.
 
        .EXAMPLE
            # Resumes a workflow
            Get-BPAWorkflow "Failed workflow" | Resume-BPAWorkflow
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 10/16/2017
            Date Modified : 02/08/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding(DefaultParameterSetName = "All",SupportsShouldProcess=$true,ConfirmImpact="High")]
    [OutputType([System.Object[]])]
    param(
        [Parameter(ValueFromPipeline = $true, ParameterSetName = "ByPipeline")]
        [ValidateNotNullOrEmpty()]
        $InputObject
    )
    PROCESS {
        foreach ($obj in $InputObject) {
            switch ($obj.TypeName) {
                "Workflow" {
                    switch ($obj.ResultCode -as [BPAInstanceStatus]) {
                        "Failed" {
                            Write-Verbose "Resuming workflow $($obj.Name)."
                            Invoke-BPARestMethod -Resource "workflows/$($obj.ConstructID)/resume" -RestMethod Post -BPAServer $obj.BPAServer
                        }
                        default {
                            if ($PSCmdlet.ShouldProcess($obj.BPAServer, "$($obj.TypeName): $(Join-Path -Path $obj.Path -ChildPath $obj.Name) is not in a failed status, and will start from the beginning.")) {
                                Write-Verbose "Starting workflow $($obj.Name)."
                                Invoke-BPARestMethod -Resource "workflows/$($obj.ConstructID)/resume" -RestMethod Post -BPAServer $obj.BPAServer
                            }
                        }
                    }
                }
                default {
                    Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj
                }
            }
        }
    }
}