使用以下步骤,可以从 Default Query Pack
上的 PowerShell 运行存储在
Log Analytics Workspace
中的 Kusto 查询。
$baseUrl = "https://management.azure.com"
$RId = (Get-AzResource -ResourceGroupName LogAnalyticsDefaultResources -Name DefaultQueryPack).ResourceId
$token = (Get-AzAccessToken -ResourceUrl $baseUrl).Token
$response = Invoke-RestMethod -Uri "$baseUrl$RId/queries?api-version=2019-09-01" -Method Get -Headers @{Authorization = "Bearer $token"}
$response.value.properties.displayname # Display names
#Runs the first query in the pack
Invoke-AzOperationalInsightsQuery -Query ($response.value)[0].properties.body -WorkspaceId <>
用户应如何使用
Invoke-AzOperationalInsightsQuery从连接到
Application Insights
的 Log Analytics Workspace
上的默认包运行查询?运行 AppInsights 查询时,我得到 Operation returned an invalid status code 'BadRequest'
。
如何使用 Invoke-AzOperationalInsightsQuery 从连接到
的Application Insights
上的默认包运行查询?Log Analytics Workspace
您可以使用
Invoke-AzOperationalInsightsQuery
在 Log Analytics 工作区上运行查询,如下所示:
Connect-AzAccount -SubscriptionId 'b83c1ed3'
$rith_workspaceId = "3c62e221"
$rith_query = @"
AzureMetrics
"@
Invoke-AzOperationalInsightsQuery -WorkspaceId $rith_workspaceId -Query $rith_query
以上
Invoke-AzOperationalInsightsQuery
仅适用于 Log Analytics 工作区及其表,不适用于 Application Insights 及其表。
在上面的 Azure Metrics 中,您可以使用从
($response.value)[-1].properties.body
的输出中获得的查询
如果您想对应用程序见解运行查询,您可以遵循此SO-Thread。
$query
的值可以赋值给($response.value)[0].properties.body
。也可以使用cli命令.