Public/Get-ALCompilerFromArtifacts.ps1

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

    $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @("version","select")
    
    try {
        $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\win32\*"
            Copy-Item -Path $binPath -Destination $alCompilerFolder
        }
        finally {
            if (Test-Path $tmpFolder) {
                Remove-Item $tmpFolder -Recurse -Force
            }

            Write-Host "AL Compiler files copied to $($alCompilerFolder)"
        }
    }
    catch {
        TrackException -telemetryScope $telemetryScope -errorRecord $_
        throw
    }
    finally {
        TrackTrace -telemetryScope $telemetryScope
    }

}

Export-ModuleMember -Function Get-ALCompilerFromArtifacts