DevOpsHandling/Get-LatestArtifactVersion.ps1

<#
 .Synopsis
  Gets the current version of an artifact
 .Description
  Returns the version of the latest artifact
 .Parameter devOpsOrganization
  Name of the organization in Azure DevOps
 .Parameter devOpsToken
  Personal access token for Azure DevOps
 .Parameter feed
  Feed to get the package from
 .Parameter packageName
  Package name to get the version from
 .Example
  $version = Get-LatestArtifactVersion -devOpsOrganization test -devOpsToken "" -packageName abc_app
#>

function Get-LatestArtifactVersion {
    Param (
        [Parameter(Mandatory=$true)]
        [string] $devOpsOrganization,
        [Parameter(Mandatory=$true)]
        [string] $devOpsToken,
        [Parameter(Mandatory=$true)]
        [string] $feed,
        [Parameter(Mandatory=$true)]
        [string] $packageName
    )

    try {
        $devOpsToken = Get-DevOpsToken -devOpsOrganization $devOpsOrganization -devOpsToken $devOpsToken

        $result = (Get-ArtifactVersion -devOpsOrganization $devOpsOrganization -devOpsToken $devOpsToken -feed $feed -packageName $packageName).versions | Where-Object { $_.isLatest -eq $true }

        $result.Version
    } catch {
        return ""
    }
}