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.


Azure PowerShell module or Azure Cloud Shell

Azure Cloud Shell is useful if you don't want to install the PowerShell module locally, as Cloud Shell performs from a browser.

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, select Try it to open the Azure Cloud Shell. Copy the script, paste into your shell, 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: centralus)"
$iotHubName = Read-Host -Prompt "Enter the IoT Hub name"

New-AzResourceGroup -Name $resourceGroupName -Location "$location"
New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateUri "" `
    -iotHubName $iotHubName


To use your own template, upload your template file to the Cloud Shell, and then use the -TemplateFile switch to specify the file name. For example, 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: