我有以下Powershell代码,用于查询Microsoft Graph api端点。 我需要设法将结果发送到Azure事件中心
$ClientID = "826fc487-212b-4e45-9fbb-8059e4b5d3ce" # Should be a ~36 hex character string; insert your info here
$ClientSecret = "9OOrzJ90Kvv97BZ3DQLQXgI/wFezmnJ8DRFMh7K/9Fs=" # Should be a ~44 character string; insert your info here
$tenantdomain = "tenant.onmicrosoft.com" # For example, contoso.onmicrosoft.com
$loginURL = "https://login.microsoft.com"
$resource = "https://graph.microsoft.com"
$body = @{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$tenantdomain/oauth2/token?api-version=1.0 -Body $body
Write-Output $oauth
if ($oauth.access_token -ne $null) {
$headerParams = @{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
$url = "https://graph.microsoft.com/beta/identityRiskEvents"
Write-Output $url
$myReport = (Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url)
foreach ($event in $myReport.Content){
$SasToken="uGllYoYHJ4etHsTh7yETy6CKFegebfXK4x3e9Lbw4+k="
Write-Output $event
}
} else {
Write-Host "ERROR: No Access Token"
}
请提出任何想法
答案 0 :(得分:0)
您的问题更接近Azure事件中心,但不更接近图,azure事件中心不提供直接通过PowerShell发送事件的方式(已知方式为NET / GO / Python),我们可以创建自定义PowerShell Binary模块C#,并在 ProcessRecord 方法中处理NET版本的“通过PowerShell发送事件”。
参考 Michael Sorens 的博客,以使您知道如何创建网络Powershell模块:https://www.red-gate.com/simple-talk/dotnet/net-development/using-c-to-create-powershell-cmdlets-the-basics/
另一个官方文档:https://docs.microsoft.com/en-us/powershell/developer/module/how-to-write-a-powershell-binary-module