Public/Get-ALCompilerFromArtifacts.ps1

function Get-ALCompilerFromArtifacts {
    param (
        [String] $Version = '',
        [ValidateSet('Latest', 'First', 'All', 'Closest', 'SecondToLastMajor', 'Current', 'NextMinor', 'NextMajor')]
        [String] $Select = 'Latest'
    )

    $alCompilerFolderName = "ALCompiler"
    $alCompilerFolder = Join-Path (Get-Location) $alCompilerFolderName
    if (Test-Path $alCompilerFolder) {
        Write-Host "AL Compiler folder already exists and won't be created."
        return
    }
    $alCompilerFolder = New-Item -Path $alCompilerFolder -ItemType "directory"

    $type = 'OnPrem'
    $artifactUrl = Get-BCArtifactUrl -version $Version -country w1 -select $Select -type $type
    $vsixFile = Get-AlLanguageExtensionFromArtifacts $artifactUrl
    Write-Verbose "vsix File: $($vsixFile)"

    Write-Host "Unpacking AL Language extension file to tmp folder." -NoNewline
    $tmpFolder = New-Item -Path ([System.IO.Path]::GetTempPath()) -Name ([Guid]::NewGuid().ToString()) -ItemType "directory"
    $vsixFileWithoutExt = [IO.Path]::GetFileNameWithoutExtension($vsixFile)
    $vsixTempFile = (Join-Path $tmpFolder "$($vsixFileWithoutExt).zip")
    Copy-Item -Path $vsixFile -Destination $vsixTempFile
    
    Write-Verbose "Temporary folder: $($tmpFolder)"
    try {
        Expand-7zipArchive -Path $vsixTempFile -DestinationPath $tmpFolder
        $binPath = Join-Path $tmpFolder "extension\bin\*"
        Copy-Item -Path $binPath -Destination $alCompilerFolder
    }
    finally {
        if (Test-Path $tmpFolder) {
            Remove-Item $tmpFolder -Recurse -Force
        }

        Write-Host "AL Compiler files copied to $($alCompilerFolder)"
    }
}

Export-ModuleMember -Function Get-ALCompilerFromArtifacts