PowerShell ile bir Log Analytics Workspace icindeki veriyi alabiliriz. Bunun icin asagidaki KQL sorgusunu PowerShell ile gonderip gelen sonucu okuyabiliriz.
Oncelikle WorkspaceID bilgisine ihtiyacimiz var. Bunun icin CustomerID bilgisini aliyoruz. Sonrasinda sorgu icerigimizi olusturup “Invoke-AzOperationalInsightsQuery” komutuyla gonderiyoruz. Ben kendi ornegimde son 2 saat icindeki Azure aktivitelerini type, ResourceProvider ve CallerIP adresine gore listeletmek istedim.
$LAWorkspaceID = (Get-AzOperationalInsightsWorkspace -Name la01 -ResourceGroupName loganalytics).customerId
$Sorgu = @’
AzureActivity
| where TimeGenerated > ago(2h)
| order by TimeGenerated desc
| project CallerIpAddress,ResourceProviderValue,Type
‘@
$Results = Invoke-AzOperationalInsightsQuery -WorkspaceId $LAWorkspaceID -Query $sorgu
$Results.results
