Public/MIT/Invoke-MITFileDownload.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Invoke-MITFileDownload
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$Id,
        [Parameter(Mandatory)]
        [string]$OutFile
    )
    $hostname = $Script:MITHostname
    $token = $Script:MITToken
    $resource = "/files/$Id/download"

    $Uri = "https://$hostname/api/v1/$Resource"
    $Headers = @{
            Accept = "application/octet-stream"
            Authorization = "Bearer $token"
        }

    $response = Invoke-RestMethod -Uri $Uri -Headers $Headers -OutFile $OutFile
    Write-Output $response
}