Create an IoT hub using Azure Resource Manager template (PowerShell)

This article shows you how to use an Azure Resource Manager template to create an IoT Hub and a consumer group, using Azure PowerShell. Resource Manager templates are JSON files that define the resources you need to deploy for your solution. For more information about developing Resource Manager templates, see the Azure Resource Manager documentation.

Prerequisites

Azure PowerShell module

Create an IoT hub

The Resource Manager JSON template used in this article is one of many templates from Azure Quickstart Templates. The JSON template creates an Azure Iot hub with three endpoints (eventhub, cloud-to-device, and messaging) and a consumer group. For more information on the Iot Hub template schema, see Microsoft.Devices (IoT Hub) resource types.

Use the following PowerShell command to create a resource group which is then used to create an IoT hub. The JSON template is used in -TemplateUri.

To run the following PowerShell script, copy the script and paste into your local Azure PowerShell, then press enter. Answer the prompts. These prompts will help you to create a new resource, choose a region, and create a new IoT hub. Once answered, a confirmation of your IoT hub prints to the console.

$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
$location = Read-Host -Prompt "Enter the location (for example: chinaeast)"
$iotHubName = Read-Host -Prompt "Enter the IoT Hub name"

New-AzResourceGroup -Name $resourceGroupName -Location "$location"
New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateUri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.devices/iothub-with-consumergroup-create/azuredeploy.json" `
    -iotHubName $iotHubName

Note

To use your own template,you can see Deploy the template.

Next steps

Since you've deployed an IoT hub, using an Azure Resource Manager template, you may want to explore:

To learn more about developing for IoT Hub, see the Azure IoT SDKs.

To explore more capabilities of IoT Hub, see: