Create an Azure Data Explorer cluster and database by using PowerShell

Azure Data Explorer is a fast, fully managed data analytics service for real-time analysis on large volumes of data streaming from applications, websites, IoT devices, and more. To use Azure Data Explorer, you first create a cluster, and create one or more databases in that cluster. Then you ingest (load) data into a database so that you can run queries against it. In this article, you create a cluster and a database by using Powershell. You can run PowerShell cmdlets and scripts on Windows, Linux, or in Azure Cloud Shell with Az.Kusto to create and configure Azure Data Explorer clusters and databases.

Prerequisites

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

If you don't have an Azure subscription, create a free account before you begin.

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article without having to install anything on your local environment.

To start Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. Example of Try It for Azure Cloud Shell
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. Launch Cloud Shell in a new window
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. Cloud Shell button in the Azure portal

To run the code in this article in Azure Cloud Shell:

  1. Start Cloud Shell.

  2. Select the Copy button on a code block to copy the code.

  3. Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

  4. Select Enter to run the code.

If you choose to install and use the Azure CLI locally, this article requires the Azure CLI version 2.0.4 or later. Run az --version to check your version. If you need to install or upgrade, see Install the Azure CLI.

Configure parameters

The following steps are not required if you're running commands in Azure Cloud Shell. If you're running the CLI locally, follow steps 1 & 2 to sign in to Azure and to set your current subscription:

  1. Run the following command to sign in to Azure:

    Connect-AzAccount
    
  2. Set the subscription where you want your cluster to be created:

     Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    
  3. When running Azure CLI locally or in the Azure Cloud Shell, you need to install the Az.Kusto module on your device:

     Install-Module -Name Az.Kusto
    

Create the Azure Data Explorer cluster

  1. Create your cluster by using the following command:

     New-AzKustoCluster -ResourceGroupName testrg -Name mykustocluster -Location 'Central US' -Sku D13_v2 -Capacity 10
    
    Setting Suggested value Field description
    Name mykustocluster The desired name of your cluster.
    Sku D13_v2 The SKU that will be used for your cluster.
    ResourceGroupName testrg The resource group name where the cluster will be created.

    There are additional optional parameters that you can use, such as the capacity of the cluster.

  2. Run the following command to check whether your cluster was successfully created:

    Get-AzKustoCluster -Name mykustocluster -ResourceGroupName testrg
    

If the result contains provisioningState with the Succeeded value, then the cluster was successfully created.

Create the database in the Azure Data Explorer cluster

  1. Create your database by using the following command:

    New-AzKustoDatabase -ResourceGroupName testrg -ClusterName mykustocluster -Name mykustodatabase -SoftDeletePeriod 3650:00:00:00 -HotCachePeriod 3650:00:00:00
    
    Setting Suggested value Field description
    ClusterName mykustocluster The name of your cluster where the database will be created.
    Name mykustodatabase The name of your database.
    ResourceGroupName testrg The resource group name where the cluster will be created.
    SoftDeletePeriod 3650:00:00:00 The amount of time that data will be kept available to query.
    HotCachePeriod 3650:00:00:00 The amount of time that data will be kept in cache.
  2. Run the following command to see the database that you created:

    Get-AzKustoDatabase -ClusterName mykustocluster -ResourceGroupName testrg -Name mykustodatabase
    

You now have a cluster and a database.

Clean up resources

  • If you plan to follow our other articles, keep the resources you created.

  • To clean up resources, delete the cluster. When you delete a cluster, it also deletes all the databases in it. Use the following command to delete your cluster:

    Remove-AzKustoCluster -ResourceGroupName testrg -Name mykustocluster
    

Next steps