Invoke-SBRDownload.ps1

function Invoke-SBRDownload(){
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [string] $ApiBaseUrl,

        [Parameter(Mandatory=$true)]
        [string] $ApiKey,

        [Parameter(Mandatory=$true)]
        [guid] $AgentUID
    )

    $TempZipFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()) + ".zip")

    #$RestError = $null

    Invoke-RestMethod -Uri "$ApiBaseUrl/api/SBRAgents/$($AgentUID)/Download" `
                      -Method Post `
                      -OutFile $TempZipFile `
                      -Headers @{"Authorization" = "Bearer " + $ApiKey} #`
                      #-ErrorVariable "RestError"

    #if ($null -ne $RestError){
    # Write-Error -Message $RestError
    #}

    return $TempZipFile
}