AL/Get-AllSymbol.ps1

<#
 .Synopsis
  Downloads Symbols for apps
 .Description
  Downloads Symbols from container for app, dependency apps, and optionally test app
 .Parameter SourcePath
  Path to the current project
 .Parameter ContainerName
  If blank, the container name will be retrieved from settings.json
 .Parameter includeTestSymbols
  Add this switch to get the test app symbols as well
 .Example
  Get-AllSymbol -SourcePath "C:\Temp" -ContainerName "container" -includeTestSymbols
#>

function Get-AllSymbol {
    Param(
        [Parameter(Mandatory=$false)]
        [string]$SourcePath = (Get-Location),
        [Parameter(Mandatory=$false)]
        [string]$ContainerName = (Get-ContainerFromLaunchJson),
        # optionally download the test symbols
        [Parameter(Mandatory=$false)]
        [switch]
        $includeTestSymbols
    )

    $PackagesPath = Join-Path $SourcePath '.alpackages'

    if (!(Test-Path $PackagesPath)) {
        New-EmptyDirectory $PackagesPath
    }

    $SymbolsDownloaded = $false

    # since BC15, system layer is defined in dependencies
    $Dependencies = Get-AppKeyValue -SourcePath $SourcePath -KeyName 'dependencies'
    if ($Dependencies) {
        foreach ($Dependency in $Dependencies) {
            if ($Dependency.publisher -eq 'Microsoft') {
                $Uri = 'http://{0}:7049/BC/dev/packages?publisher={1}&appName={2}&versionText={3}' -f $ContainerName, $Dependency.publisher, $Dependency.name, $Dependency.version
                Write-Output $Uri
                Invoke-WebRequest -Uri $Uri -Headers (New-Header) -OutFile (Join-Path $PackagesPath ('{0}_{1}_{2}.app' -f $Dependency.publisher, $Dependency.name, $Dependency.version))
                $SymbolsDownloaded = $true
            }
        }
    }

    if ($SymbolsDownloaded) {
        $Uri = 'http://{0}:7049/BC/dev/packages?publisher=Microsoft&appName=System&versionText={1}' -f $ContainerName, (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform')
        Write-Output $Uri
        Invoke-WebRequest -Uri $Uri -Headers (New-Header) -OutFile (Join-Path $PackagesPath ('Microsoft_System_{0}.app' -f (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform')))
    }
    # prior to BC15, system layer defined through properties in app.json
    else {
        $Uri = 'http://{0}:7049/NAV/dev/packages?publisher=Microsoft&appName=Application&versionText={1}' -f $ContainerName, (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'application')
        Write-Output $Uri
        Invoke-WebRequest -Uri $Uri -Headers (New-Header) -OutFile (Join-Path $PackagesPath ('Microsoft_Application_{0}.app' -f (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'application')))

        $Uri = 'http://{0}:7049/NAV/dev/packages?publisher=Microsoft&appName=System&versionText={1}' -f $ContainerName, (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform')
        Write-Output $Uri
        Invoke-WebRequest -Uri $Uri -Headers (New-Header) -OutFile (Join-Path $PackagesPath ('Microsoft_System_{0}.app' -f (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'platform')))

        if ($includeTestSymbols.IsPresent) {
            $Uri = 'http://{0}:7049/NAV/dev/packages?publisher=Microsoft&appName=Test&versionText={1}' -f $ContainerName, (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'test')
            Write-Output $Uri
            Invoke-WebRequest -Uri $Uri -Headers (New-Header) -OutFile (Join-Path $PackagesPath ('Microsoft_Test_{0}.app' -f (Get-AppKeyValue -SourcePath $SourcePath -KeyName 'test')))
        }
    }
}

function New-Header
{
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact="low")]
    [OutputType([System.Collections.Hashtable])]
    Param()
    if ($PSCmdlet.ShouldProcess("Authorization", "Adding authorization headers to ")) {
        $ba = '{0}:{1}' -f (Get-EnvironmentKeyValue -KeyName 'user'), (Get-EnvironmentKeyValue -KeyName 'password')
        $ba = [System.Text.Encoding]::UTF8.GetBytes($ba)
        $ba = [System.Convert]::ToBase64String($ba)
        $h = @{Authorization=("Basic {0}" -f $ba);'Accept-Encoding'='gzip,deflate'}
        $h
    }
}

Export-ModuleMember -Function Get-AllSymbol