DevOpsHandling/Get-DevOpsArtifactsFromFeed.ps1

function Get-DevOpsArtifactsFromFeed {
    Param(
        [Parameter(Mandatory=$true)]
        [string]$devOpsOrganization,
        [Parameter(Mandatory=$true)]
        [string]$devOpsFeed,
        [Parameter(Mandatory=$true)]
        [string]$devOpsArtifact,
        [Parameter(Mandatory=$true)]
        [string]$devOpsToken,
        [Parameter(Mandatory=$true)]
        [string]$destination
    )

    $appsList = [System.Collections.ArrayList]@()

    $artifacts = (Invoke-AzureDevOpsApi -url ('https://feeds.dev.azure.com/{0}/_apis/packaging/Feeds/{1}/packages' -f $devOpsOrganization, $devOpsFeed) -devOpsToken $devOpsToken).value
    
    foreach($artifact in $artifacts | Where-Object Name -eq $devOpsArtifact) {
        $versions = (Invoke-AzureDevOpsApi -url ('https://feeds.dev.azure.com/{0}/_apis/packaging/Feeds/{1}/Packages/{2}/versions?includeUrls-true&isDeleted=false' -f $devOpsOrganization, $devOpsFeed, $artifact.id) -devOpsToken $devOpsToken).value
        $version = ($versions | Where-Object isLatest -eq $true)

        $app = (Invoke-AzureDevOpsApi -url $version.url -destination $destination -outfile (Join-Path $destination "$($artifact.Name).app") -devOpsToken $devOpsToken)
        [void]$appsList.Add($app)
    }

    return $appsList
}
Export-ModuleMember Get-DevOpsArtifactsFromFeed