Kusto.Cli is a powerful command-line utility designed to interact with Kusto clusters, enabling users to send queries and control commands efficiently. This tool is particularly useful for automating tasks that typically require writing code, such as C# programs or PowerShell scripts. In this blog post, we'll explore the various modes, features, and commands of Kusto.Cli, providing a comprehensive guide to harnessing its capabilities.
Modes of Operation
Kusto.Cli operates in three primary modes:
REPL Mode: This mode allows users to enter queries and commands interactively. The tool displays the results and awaits the next input, making it ideal for exploratory data analysis.
Execute Mode: Users can specify one or more queries and commands as command-line arguments. These are executed sequentially, and the results are output to the console. Optionally, the tool can switch to REPL mode after executing all commands.
Script Mode: Similar to execute mode, but queries and commands are specified in a script file. This mode is perfect for running predefined sets of commands.
Getting Started
To use Kusto.Cli, download the Microsoft.Azure.Kusto.Tools NuGet package and extract the tools folder to your target directory. No additional installation is required. The basic command to run Kusto.Cli is:
Kusto.Cli.exe "<ConnectionString>"
Command-Line Arguments
Kusto.Cli supports various command-line arguments to customize its behavior:
ConnectionString: Specifies the Kusto connection string.
-execute: Runs the specified query or command.
-script: Executes commands from a script file.
-keepRunning: Enables or disables REPL mode after executing commands.
-echo: Enables or disables echo mode, repeating queries or commands in the output.
-transcript: Writes program output to a specified file.
-logToConsole: Enables or disables console output.
-lineMode: Determines how newlines are treated in input queries or commands.
Directives
Kusto.Cli includes several directives for controlling its behavior:
#help: Displays a short help message.
#quit: Exits the tool.
#connect: Connects to a different Kusto service.
#dbcontext: Changes the context database.
#save: Saves query results to a CSV file.
#script: Executes a script file.
Example Usage
Here's an example of using Kusto.Cli to export query results to a CSV file:
Kusto.Cli.exe "<ConnectionString>" -execute:"#save c:\temp\results.csv" -execute:"StormEvents | take 10"
TLDR
Kusto.Cli is a versatile tool that simplifies interaction with Kusto clusters through its command-line interface. Whether you're performing exploratory data analysis, automating tasks, or running predefined scripts, Kusto.Cli offers the flexibility and power needed to streamline your workflow. By understanding its modes, command-line arguments, and directives, you can fully leverage Kusto.Cli to enhance your data querying capabilities.