functions/Invoke-Analysis.ps1

<#
.SYNOPSIS
Invoke an analysis of an uploaded file
 
.DESCRIPTION
Used to invoke an analysis of a file payload against a given project. Can be used to upload source code and/or previous scan results.
  
.EXAMPLE
Invoke-Analysis [file_to_process] [project_id]
Invoke-Analysis .\mysource.zip 12
Invoke-Analysis .\burp_results.xml 12
 
Output
HttpResponse
#>


function Invoke-Analysis
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]
        $FilePathToAnalyze
        ,
        [Parameter(Mandatory=$true)]
        [int32]
        $projectID
    )
    
    #https://<yourcodedxserver>/codedx/api/projects/<project id>/analysis
    $uri = $CDXSERVER + "/api/projects/" + $projectID + "/analysis"

        $fileBytes = [System.IO.File]::ReadAllBytes($FilePathToAnalyze);
        $fileEnc = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytes);
        $boundary = [System.Guid]::NewGuid().ToString(); 
        $LF = "`r`n";

        $bodyLines = ( 
            "--$boundary",
            "Content-Disposition: form-data; name=`"file1`"; filename=`"temp.txt`"",
            "Content-Type: application/octet-stream$LF",
            $fileEnc,
            "--$boundary--$LF" 
        ) -join $LF

    Write-Verbose $uri
    Write-Verbose $APIKEY
    Write-Verbose $LF
    #Write-Verbose $bodyLines
    Write-Verbose $boundary
                  
    $AnalysisID = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -ContentType "multipart/form-data; boundary=$boundary" -Body $bodyLines # -InFile $FilePathToAnalyze

    Write-Verbose ( $AnalysisJobInfo | Format-Table | Out-String )

    return $AnalysisID
}