DevOpsHandling/Get-DevOpsArtifactList.ps1

<#
 .Synopsis
  Download artifacts from Azure DevOps
 .Description
  Downloads artifacts from a given project and repository and extracts them to a specified directory
 .Parameter devOpsOrganization
  Name of the organization in Azure DevOps the artifacts are contained in
 .Parameter devOpsFeed
  Name of the artifact feed
 .Parameter devOpsArtifact
  Name of the artifact
 .Parameter devOpsToken
  Personal access token for Azure DevOps
 .Parameter destination
  Local folder the artifacts should be stored in
 .Example
  Get-DevOpsArtifactList -devOpsOrganization test -devOpsProjectName test -devOptsToken "1234567890" -destination "C:\Temp\"
 .Example
  Get-DevOpsArtifactList -devOpsOrganization test -devOpsProjectName test -repositoryName repo -devOptsToken "1234567890" -destination "C:\Temp\"
#>

function Get-DevOpsArtifactList {
    Param(
        [Parameter(Mandatory = $false)]
        [string] $devOpsOrganization = "",
        [Parameter(Mandatory = $true)]
        [string] $devOpsFeed,
        [Parameter(Mandatory = $true)]
        [string] $devOpsArtifactName,
        [Parameter(Mandatory = $false)]
        [string] $devOpsToken = "",
        [Parameter(Mandatory = $true)]
        [string] $destination,
        [Parameter(Mandatory = $false)]
        [string] $version = ""
    )

    $devOpsToken = Get-DevOpsToken -SourcePath (Get-Location) -devOpsOrganization $devOpsOrganization -devOpsToken $devOpsToken

    if (!(Test-Path $destination)) {
        New-Item -Path $destination -ItemType Directory | Out-Null
    }

    $version = Get-NormalizedVersion -version $version

    try {
        $apps = Get-DevOpsArtifactsFromFeed -devOpsOrganization $devOpsOrganization -devOpsFeed $devOpsFeed -devOpsArtifact $devOpsArtifactName -version $version -destination $destination
    }
    catch {
        [Console]::ForegroundColor = "Gray"
        # get the latest version from the feed for the pacakge and then use that to download it
        $version = Get-LatestArtifactVersion -devOpsOrganization $devOpsOrganization -devOpsToken $devOpsToken -feed $devOpsFeed -packageName $devOpsArtifactName
        if ($version -eq "") {
            $version = "*"
        }

        $apps = Get-DevOpsArtifactsFromFeed -devOpsOrganization $devOpsOrganization -devOpsFeed $devOpsFeed -devOpsArtifact $devOpsArtifactName -version $version -destination $destination
    }

    return $apps
}