繁体   English   中英

PowerShell function 查询Azure Data Explorer

[英]PowerShell function to query Azure Data Explorer

PowerShell function Invoke-AzOperationalInsightsQuery 文档允许我将任意 KQL 字符串传递给 App Insights 资源。

Set-AzContext -Subscription "my-sub"
$workspaceName = "vl-loganalytics-workspace"
$workspaceRG = "vl-loganalytics"

$WorkspaceID = (Get-AzOperationalInsightsWorkspace -Name $workspaceName -ResourceGroupName $workspaceRG).CustomerID

$query = "print current_cluster_endpoint()"

$kqlQuery = Invoke-AzOperationalInsightsQuery -WorkspaceId $WorkspaceID -Query $query
$kqlQuery.Results

HT 边做边学.cloud

是否存在直接查询 Azure Data Explorer 集群的等效方法? 自 2.1.0 版起, Az.Kusto模块中未列出公共 function,但也许有一个社区模块或博客文章记录了一个专门的方法?

从 PowerShell 引用 Kusto .NET 客户端库,在下载和解压缩Microsoft.Azure.Kusto.Tools NuGet package后,使用以下帮助程序代码是可能的

$clusterUrl = 'https://help.kusto.windows.net;Fed=True'
$databaseName = 'Samples'
$query = 'print current_cluster_endpoint()'

$packagesRoot = Resolve-Path "tools\net6.0"
[System.Reflection.Assembly]::LoadFrom("$packagesRoot\Kusto.Data.dll")

$kcsb = New-Object Kusto.Data.KustoConnectionStringBuilder ($clusterUrl, $databaseName)

$queryProvider = [Kusto.Data.Net.Client.KustoClientFactory]::CreateCslQueryProvider($kcsb)

$crp = New-Object Kusto.Data.Common.ClientRequestProperties
$crp.ClientRequestId = "MyPowershellScript.ExecuteQuery." + [Guid]::NewGuid().ToString()
$crp.SetOption([Kusto.Data.Common.ClientRequestProperties]::OptionServerTimeout, [TimeSpan]::FromSeconds(30))

$reader = $queryProvider.ExecuteQuery($query, $crp)
$dataTable = [Kusto.Cloud.Platform.Data.ExtendedDataReader]::ToDataSet($reader).Tables[0]
$dataView = New-Object System.Data.DataView($dataTable)

$dataView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM