Darktrace API - Powershell example

Here's an example code snippet to make an API call to Darktrace using Powershell. Find the instances of 'changeme' and change to the correct value.

$Time = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")
$PrivateToken = "changeme"
$PublicToken = "changeme"
$Request = "/status?fast=true&includechildren=false"

$AuthSig = "$Request`n$PublicToken`n$Time"
$HMACBytes = [System.Text.Encoding]::UTF8.GetBytes($AuthSig)
$HMAC = New-Object System.Security.Cryptography.HMACSHA1
$HMAC.Key = [System.Text.Encoding]::UTF8.GetBytes($PrivateToken)
$HashBytes = $HMAC.ComputeHash($HMACBytes)
$HMAC.Dispose()
$HMACHex = [BitConverter]::ToString($HashBytes) -replace "-"

Write-Host $HMACHex

$DarktraceHost = "https://darktrace.changeme.com"

$Headers = @{
    "DTAPI-Token" = $PublicToken
    "DTAPI-Date" = $Time
    "DTAPI-Signature" = $HMACHex
    }

Invoke-RestMethod -Uri "$DarktraceHost$Request" -Headers $Headers -Method Get -UseBasicParsing