Public/Get-DuneDeploymentSequence.ps1

<#
.SYNOPSIS
Retrieve deployment sequences for a deployment.

.DESCRIPTION
Gets sequence objects for a specific deployment. You may identify the deployment by `Id` or by passing a `DuneDeployment` object from the pipeline. Supports filtering by usage and returns `DuneSequence` objects unless `-Raw` is used.

.PARAMETER Id
The GUID of the deployment whose sequences should be returned. Mandatory in the `Id` parameter set.

.PARAMETER Deployment
A `DuneDeployment` object; use this parameter (or pipeline input) to return sequences for the provided deployment.

.PARAMETER Usage
Filter sequences by `SequenceUsage`.

.PARAMETER Raw
If set, returns raw API objects instead of `DuneSequence` objects.

.EXAMPLE
PS> Get-DuneDeploymentSequence -Id 3d8f6b5a-...
Returns sequences for the deployment with the given `Id`.

.EXAMPLE
PS> Get-DuneDeployment -Name "MyApp" | Get-DuneDeploymentSequence
Pipeline example using the `Deployment` parameter set.
#>

function Get-DuneDeploymentSequence {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter(Mandatory, ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "Deployment", ValueFromPipeline)]
        [DuneDeployment]$Deployment,

        [Parameter()]
        [SequenceUsage]$Usage,

        [Parameter()]
        [switch]$Raw
    )

    begin {
        Write-Debug "$($MyInvocation.MyCommand)|begin"
        $ReturnObjects = @()
        $BaseUri = 'deployments/{0}/sequences'
        $Method = 'GET'
    }

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"

        if ($PSCmdlet.ParameterSetName -eq 'Deployment') {
            $Id = $Deployment.Id
        }

        # Build Uri
        $Uri = $BaseUri -f $Id

        $ResultItems = Invoke-DuneApiRequest -Method $Method -Uri $Uri -ExtractItems
        $ReturnObjects += $ResultItems | ForEach-Object {
            if ($Raw) {
                $_
            }
            else {
                ConvertTo-DuneClassObject -Class DuneSequence -InputObject $_
            }
        }

        # Filter for Usage
        if ($Usage) { $ReturnObjects = $ReturnObjects | Where-Object Usage -eq $Usage }

    }

    end {
        Write-Debug "$($MyInvocation.MyCommand)|end"
        return $ReturnObjects
    }
}