Skip to content

About

Script para mandar consultas a log analytics y exportar los resultados a un json

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

LogAnalytics Extractor

PowerShell script to execute KQL queries against an Azure Log Analytics workspace and export the results to JSON.

Requirements

  • PowerShell 7+
  • Azure PowerShell modules:
Install-Module Az.Accounts, Az.OperationalInsights -Scope CurrentUser

Setup

  1. Copy .env.example to .env and fill in your values:
WORKSPACE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
TENANT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx       # optional
SUBSCRIPTION_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # optional
  1. Write your KQL query in a .kql file.

Usage

.\Invoke-LogAnalyticsQuery.ps1 -QueryFile .\query.kql -OutputFile .\results.json

With a custom config file:

.\Invoke-LogAnalyticsQuery.ps1 -QueryFile .\query.kql -OutputFile .\results.json -ConfigFile .\prod.env

Parameters

Parameter Required Description
-QueryFile Yes Path to the .kql file containing the query
-OutputFile Yes Path for the JSON output file
-ConfigFile No Path to the .env config file (default: .env)

Output format

{
  "metadata": {
    "queryFile": "C:\\path\\to\\query.kql",
    "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "executedAt": "2026-05-11T10:00:00.000Z",
    "rowCount": 200
  },
  "results": [
    { ... }
  ]
}

Notes

  • If there is an active Azure session it will be reused; otherwise an interactive login prompt will appear.
  • The .env file and all *.json result files are excluded from version control via .gitignore.

About

Script para mandar consultas a log analytics y exportar los resultados a un json

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages