Scripts/Get-BPAWorkflowVariable.ps1

function Get-BPAWorkflowVariable {
    <#
        .SYNOPSIS
            Gets a list of variables within a workflow.
 
        .DESCRIPTION
            Get-BPAWorkflowVariable retrieves variables for a workflow.
 
        .PARAMETER InputObject
            The object to retrieve variables from.
 
        .PARAMETER Name
            Search on the name of the variable. Wildcards are accepted.
 
        .PARAMETER InitialValue
            Search on the initial value of the variable. Wildcards are accepted.
 
        .INPUTS
            The following BPA object types can be queried by this function:
            Workflow
 
        .EXAMPLE
            # Get variables in workflow "FTP Files"
            Get-BPAWorkflow "FTP Files" | Get-BPAWorkflowVariable
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 07/24/2017
            Date Modified : 02/27/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

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

        [string]$Name = "*",

        [string]$InitialValue = "*"
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            if ($obj.TypeName -eq "Workflow") {
                foreach ($var in $obj.Variables) {
                    if (($var.Name -like $Name) -and ($var.InitalValue -like $InitialValue)) {
                        $temp = $var.PSObject.Copy()
                        $temp | Add-Member -NotePropertyName "WorkflowName" -NotePropertyValue $obj.Name
                        $temp | Add-Member -NotePropertyName "TypeName"     -NotePropertyValue ($temp.Type -as [BPAConstructType])
                        $temp | Add-Member -NotePropertyName "BPAServer"    -NotePropertyValue $obj.BPAServer
                        $temp.PSObject.TypeNames.Insert(0,"BPAConstructType.WorkflowVariable")
                        $temp
                    }
                }
            } else {
                Write-Error -Message "Unsupported input type '$($obj.TypeName)' encountered!" -TargetObject $obj
            }
        }
    }
}