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>]
Description
Invoke-AzOperationalInsightsQuery Cmdlet 會根據指定的參數傳回搜尋結果。 您可以在傳回物件的 Metadata 屬性中存取搜尋的狀態。 如果狀態為 [擱置],則搜尋尚未完成,且結果會來自封存。 您可以從傳回物件的 Value 屬性擷取搜尋的結果。 請在這裡檢視一般查詢限制的詳細資料:https://learn.microsoft.com/azure/azure-monitor/service-limits#log-queries-and-language。
注意:如果您遇到「因為已設定的 HttpClient.Timeout 為 100 秒超過 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
工作區標識碼。
類型: | String |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | False |
接受萬用字元: | False |