Skip to content

Instantly share code, notes, and snippets.

@nathanmcnulty
Created November 22, 2025 01:16
Show Gist options
  • Select an option

  • Save nathanmcnulty/39670f0adec2da5d0a6773c47cf14d3f to your computer and use it in GitHub Desktop.

Select an option

Save nathanmcnulty/39670f0adec2da5d0a6773c47cf14d3f to your computer and use it in GitHub Desktop.
Get MTP API token using Azure PowerShell
$tenantId = "YOUR-TENANTID"
$fullToken = Get-AzAccessToken -ResourceUrl "https://securitycenter.microsoft.com/mtp" -TenantId $tenantId
$secureToken = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($fullToken.Token)
try {
$token = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($secureToken)
} finally {
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($secureToken)
}
$headers = @{ authorization= "Bearer $token" }
Invoke-Restmethod -Uri "https://mde-dtc-snsexclusions-prd-eus3.securitycenter.windows.com/api/sense-collection/rules" -Headers $headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment