Public/MIT/Connect-MITServer.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Connect to a MITServer.
function Connect-MITServer
{
    [CmdLetBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$Hostname,
        [Parameter(Mandatory)]
        [string]$Username,
        [Parameter(Mandatory)]
        [string]$Password
    )

    $params = @{
        Uri = "https://$Hostname/api/v1/token"
        Method = 'POST'
        ContentType = 'application/x-www-form-urlencoded'
        Body = "grant_type=password&username=$Username&password=$Password"
        Headers = @{Accept = "application/json"}
    }

    $response = Invoke-RestMethod @params
    Set-MITSession -Hostname $Hostname -Token $response.access_token
}