Modules/businessdev.ALbuild.Containers/Public/Get-BcArtifactVersion.ps1

function Get-BcArtifactVersion {
    <#
    .SYNOPSIS
        Parses the type, version and country out of a Business Central artifact URL.
 
    .PARAMETER ArtifactUrl
        An artifact URL of the form https://.../{type}/{version}/{country}.
 
    .EXAMPLE
        Get-BcArtifactVersion 'https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/25.1.12345.0/w1'
 
    .OUTPUTS
        PSCustomObject with Type, Version ([version]), Country, Url.
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [string] $ArtifactUrl
    )

    process {
        $segments = ([uri]$ArtifactUrl).AbsolutePath.Trim('/').Split('/')
        if ($segments.Count -lt 3) {
            throw "'$ArtifactUrl' is not a valid Business Central artifact URL (expected .../{type}/{version}/{country})."
        }

        $parsedVersion = [version]'0.0.0.0'
        if (-not [version]::TryParse($segments[1], [ref] $parsedVersion)) {
            throw "'$($segments[1])' in '$ArtifactUrl' is not a valid version."
        }

        return [PSCustomObject]@{
            Type    = $segments[0]
            Version = $parsedVersion
            Country = $segments[2]
            Url     = $ArtifactUrl
        }
    }
}