你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Invoke-AzOperationalInsightsQuery
基于指定的参数返回搜索结果。
语法
Invoke-AzOperationalInsightsQuery
-WorkspaceId <String>
-Query <String>
[-Timespan <TimeSpan>]
[-Wait <Int32>]
[-IncludeRender]
[-IncludeStatistics]
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Invoke-AzOperationalInsightsQuery
-Workspace <PSWorkspace>
-Query <String>
[-Timespan <TimeSpan>]
[-Wait <Int32>]
[-IncludeRender]
[-IncludeStatistics]
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
说明
Invoke-AzOperationalInsightsQuery cmdlet 基于指定的参数返回搜索结果。 可以在返回对象的 Metadata 属性中访问搜索的状态。 如果状态为“挂起”,则搜索尚未完成,结果将从存档中获取。 可以从返回对象的 Value 属性检索搜索结果。 请查看此处的常规查询限制的详细信息:https://learn.microsoft.com/azure/azure-monitor/service-limits#log-queries-and-language。
注意:如果遇到错误“由于配置的 HttpClient.Timeout 为 100 秒,请求已取消”,请尝试将 -Wait
设置为更大的值。
示例
示例 1:使用查询获取搜索结果
$query = "union * | take 10"
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId "63613592-b6f7-4c3d-a390-22ba13102111" -Query $query
$queryResults.Results
调用后,$queryResults.Results 将包含查询中的所有生成的行。
示例 2:转换$results。数组的结果 IEnumerable
$query = "union * | take 10"
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId "63613592-b6f7-4c3d-a390-22ba13102111" -Query $query
$resultsArray = [System.Linq.Enumerable]::ToArray($queryResults.Results)
某些查询可能会导致返回非常大的数据集。 因此,cmdlet 的默认行为是返回 IEnumerable 以降低内存成本。 如果希望获得结果数组,可以使用 LINQ Enumerable.ToArray() 扩展方法将 IEnumerable 转换为数组。
示例 3:在特定时间范围内使用查询获取搜索结果
$query = "union * | take 10"
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId "63613592-b6f7-4c3d-a390-22ba13102111" -Query $query -Timespan (New-TimeSpan -Hours 24)
$queryResults.Results
此查询的结果将限制为过去 24 小时。
示例 4:在查询结果中包含呈现 & 统计信息
$query = "union * | take 10"
$queryResults = Invoke-AzOperationalInsightsQuery -WorkspaceId "63613592-b6f7-4c3d-a390-22ba13102111" -Query $query -IncludeRender -IncludeStatistics
$queryResults.Results
$queryResults.Render
$queryResults.Statistics
参数
-AsJob
在后台运行 cmdlet
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-DefaultProfile
用于与 Azure 通信的凭据、帐户、租户和订阅。
类型: | IAzureContextContainer |
别名: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-IncludeRender
如果指定,则指标查询的呈现信息将包含在响应中。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-IncludeStatistics
如果指定,查询统计信息将包含在响应中。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Query
要执行的查询。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-Timespan
要绑定查询依据的时间跨度。
类型: | Nullable<T>[TimeSpan] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Wait
将上限放在服务器处理查询所花费的时间量上。 请参阅:https://learn.microsoft.com/azure/azure-monitor/logs/api/timeouts
类型: | Nullable<T>[Int32] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Workspace
工作区
类型: | PSWorkspace |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-WorkspaceId
工作区 ID。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |