functions/appdev/Get-BcSymbol.ps1

function Get-BcSymbol
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [string]$Authentication = 'UserPassword',
        [string]$UserPassKeyValuePair = 'admin:P@ssword1',
        [string]$DeveloperServicesBaseUrl = 'http://bcnextmajor:7049',
        [string]$ServerInstance = 'BC',
        [string]$Tenant = 'default',
        [string]$Publisher = 'Microsoft',
        [string]$AppName = 'System',
        [string]$Version = '25.0.0.0',
        [string]$AlpackagesDirectory = (Join-Path $Env:TEMP '.alpackages')
    )

    if (-not (Test-Path -Path $AlpackagesDirectory -PathType Container))
    {
        New-Item -Path $AlpackagesDirectory -ItemType Directory -Force | Out-Null
    }

    $AppUrl = "$($DeveloperServicesBaseUrl)/$($ServerInstance)/dev/packages?publisher=$($Publisher)&appName=$($AppName)&versionText=$($Version)&tenant=$($Tenant)"
    $AppFile = "$($AlpackagesDirectory)\$($Publisher)_$($AppName)_$($Version).app"

    if ($Authentication -eq 'UserPassword')
    {
        $EncodedAuthorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($UserPassKeyValuePair))
        $Headers = @{ Authorization = "Basic $($EncodedAuthorization)" }
    } else {
        throw 'UserPassword is the only supported authentication method at this time. Sorry!'
    }

    $Response = Invoke-WebRequest $AppUrl -OutFile "$($AppFile)" -Headers $Headers -PassThru

    [string]$ContentDisposition = $Response.Headers.'Content-Disposition'
    $FileName = (Join-Path "$($AlpackagesDirectory)" "$((Get-FilenameFromContentDisposition -ContentDisposition $ContentDisposition).Trim('"'))")

    if ($AppFile -ne $FileName)
    {
        Move-Item -Path $AppFile -Destination $FileName -Force
    }

    Write-Output $FileName
}

# Example usage:
# Get-BcSymbol -AppName Application -Version 0.0.0.0