functions/Get-JobResult.ps1

<#
.SYNOPSIS
  
Returns Job Result for given Job Identifier and saves it to a file.
  
.DESCRIPTION
Returns Job Result for given Job Identifier. The response could be binary or it oculd be string data. The headers will match the body.
Body of the reponse will be saved to the provided directory.
  
.EXAMPLE
Get-JobResult "asdf8sfsd98sa8sd9a9f" "C:\my folder\reportfilename"
 
Output
string($binary)
#>


Function Get-JobResult
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$JobID,
        [Parameter(Mandatory=$true)]
        [string]$OutputFilePath
    )

    $JobID = $JobID.ToLower()
    $OutputFilePath = $OutputFilePath.Trim("""")

    $uri = $CDXSERVER + "/api/jobs/" + $JobID + "/result"

    $JobResult = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -ContentType "application/json" -outfile $OutputFilePath

    Write-Verbose ( $JobResult | Format-Table | Out-String )
    Return $JobResult
}