Public/Get-M365KustoToken.ps1
|
function Get-M365KustoToken { <# .SYNOPSIS Acquires a Kusto access token from the current Az context. .DESCRIPTION Requires an active Az context (Managed Identity or interactive login). .OUTPUTS [string] Bearer access token #> [CmdletBinding()] param() Write-M365Log "Acquiring Kusto access token..." $tokenResponse = Get-AzAccessToken -ResourceUrl "https://kusto.kusto.windows.net" -ErrorAction Stop if ($tokenResponse.Token -is [System.Security.SecureString]) { $token = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto( [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($tokenResponse.Token) ) } else { $token = $tokenResponse.Token } Write-M365Log "Successfully acquired Kusto access token" return $token } |