DevOpsHandling/Get-DevOpsArtifacts.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-DevOpsArtifacts -devOpsOrganization test -devOpsProjectName test -devOptsToken "1234567890" -destination "C:\Temp\"
 .Example
  Get-DevOpsArtifacts -devOpsOrganization test -devOpsProjectName test -repositoryName repo -devOptsToken "1234567890" -destination "C:\Temp\"
#>

function Get-DevOpsArtifacts {
    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 = ""
    )
 
    if ($devOpsOrganization -eq "") {
        $devOpsOrganization = Get-EnvironmentKeyValue -KeyName "Organization"
    }
    if ($devOpsToken -eq "") {
        $devOpsToken = Get-EnvironmentKeyValue -KeyName "token"
    }
    if (!(Test-Path $destination)) {
        New-Item -Path $destination -ItemType Directory | Out-Null
    }
    if ($version -ne "") {
        $version = "{0}.{1}.{2}" -f ([version]$version).Major, ([version]$version).Minor, ([version]$version).Build
    }
    else {
        $version = "*"
    }
    $apps = Get-DevOpsArtifactsFromFeed -devOpsOrganization $devOpsOrganization -devOpsFeed $devOpsFeed -devOpsArtifact $devOpsArtifactName -devOpsToken $devOpsToken -version $version -destination $destination

    return $apps
}
Export-ModuleMember -function Get-DevOpsArtifacts