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 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
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 "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.devices/iothub-with-consumergroup-create/azuredeploy.json" ` -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.
Since you've deployed an IoT hub, using an Azure Resource Manager template, you may want to explore:
- Capabilities of the IoT Hub resource provider REST API
- Capabilities of the Azure Resource Manager
- JSON syntax and properties to use in templates: Microsoft.Devices resource types
To learn more about developing for IoT Hub, see:
To explore more capabilities of IoT Hub, see:
Submit and view feedback for