Scripts/Get-BPAWorkflowLink.ps1

function Get-BPAWorkflowLink {
    <#
        .SYNOPSIS
            Gets a list of links within a workflow.
 
        .DESCRIPTION
            Get-BPAWorkflowLink retrieves links for a workflow.
 
        .PARAMETER InputObject
            The object to retrieve links from.
 
        .PARAMETER LinkType
            Only retrieve variables of a specific link type.
 
        .PARAMETER IgnoreLabels
            If workflow items are configured to use labels, ignore the label and show the item type and name.
 
        .INPUTS
            The following BPA object types can be queried by this function:
            Workflow
 
        .EXAMPLE
            # Get links in workflow "FTP Files"
            Get-BPAWorkflow "FTP Files" | Get-BPAWorkflowLink
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 07/24/2017
            Date Modified : 06/15/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline = $true)]
        [ValidateNotNullOrEmpty()]
        $InputObject,

        [BPALinkType]$LinkType,

        [switch]$IgnoreLabels = $false
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            if ($obj.TypeName -eq "Workflow") {
                # Sort links by X/Y location in the WFD, assuming that most people design from left to right, and from top to bottom. This will sort the output in a more meaningful order.
                $allLinks = $obj.Links | Select-Object *,@{Name="SourceX";Expression={$_.SourcePoint.X}}, `
                                                         @{Name="SourceY";Expression={$_.SourcePoint.Y}}, `
                                                         @{Name="DestX";Expression={$_.DestinationPoint.X}}, `
                                                         @{Name="DestY";Expression={$_.DestinationPoint.Y}} | Sort-Object SourceX,DestX,SourceY,DestY
                if ($PSBoundParameters.Keys -contains "LinkType") {
                    $allLinks = $allLinks | Where-Object {$_.LinkType -eq $LinkType.value__}
                }                
                $allItems = $obj.Items + $obj.Triggers
                foreach ($link in $allLinks) {
                    $sourceItem = $allItems | Where-Object {$_.ID -eq $link.SourceID}
                    $destItem   = $allItems | Where-Object {$_.ID -eq $link.DestinationID}
                    
                    if ($sourceItem.UseLabel -and (-not $IgnoreLabels.ToBool())) {
                        $sourceObj = $sourceItem.Label
                    } else {
                        switch ($sourceItem.ConstructType -as [BPAConstructType]) {
                            "Evaluation" {
                                $sourceObj = "Evaluation : $($sourceItem.Expression)"
                            }
                            "Wait" {
                                $sourceObj = "Wait"
                            }
                            default {
                                $sourceObj = "$($sourceItem.ConstructType -as [BPAConstructType]) : $((Invoke-BPARestMethod -Resource "$(([BPATypeDictionary]::($sourceItem.ConstructType -as [BPAConstructType])).RestResource)/$($sourceItem.ConstructID)/get" -BPAServer $obj.BPAServer).Name)"
                            }
                        }
                    }
                    if ($destItem.UseLabel -and (-not $IgnoreLabels.ToBool())) {
                        $destObj = $destItem.Label
                    } else {
                        switch ($destItem.ConstructType -as [BPAConstructType]) {
                            "Evaluation" {
                                $destObj = "Evaluation : $($destItem.Expression)"
                            }
                            "Wait" {
                                $destObj = "Wait"
                            }
                            default {
                                $destObj = "$($destItem.ConstructType -as [BPAConstructType]) : $((Invoke-BPARestMethod -Resource "$(([BPATypeDictionary]::($destItem.ConstructType -as [BPAConstructType])).RestResource)/$($destItem.ConstructID)/get" -BPAServer $obj.BPAServer).Name)"
                            }
                        }
                    }                    
                    switch ($link.LinkType -as [BPALinkType]) {
                        "Result" {
                            switch ($link.ResultType -as [BPALinkResultType]) {
                                {$_ -in @("Default", "True", "False")} {
                                    $linkInfo = "$($link.LinkType -as [BPALinkType]) : $_"
                                }
                                "Value" {
                                    $linkInfo = "$($link.LinkType -as [BPALinkType]) : $($link.Value) (value)"
                                }
                            }
                            
                        }
                        default {
                            $linkInfo = "$($link.LinkType -as [BPALinkType])"
                        }
                    }
                    [PSCustomObject]@{
                        WorkflowName = $obj.Name
                        Source       = $sourceObj
                        Link         = $linkInfo
                        Destination  = $destObj
                    }
                }
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj
            }
        }
    }
}