title: Create an Azure IoT Hub using a template (PowerShell) | Microsoft Docs description: How to use an Azure Resource Manager template to create an IoT Hub with Azure PowerShell. author: robinsh manager: philmea ms.author: robinsh ms.service: iot-hub services: iot-hub ms.topic: conceptual ms.date: 04/02/2019
[!INCLUDE iot-hub-resource-manager-selector]
Learn how to use an Azure Resource Manager template to create an IoT Hub and a consumer group. 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 Azure Resource Manager documentation.
If you don't have an Azure subscription, create a free account before you begin.
The Resource Manager template used in this quickstart is from Azure Quickstart templates. Here is a copy of the template:
[!code-jsoniothub-creation]
The template creates an Azure Iot hub with three endpoints (eventhub, cloud-to-device, and messaging), and a consumer group. For more template samples, see Azure Quickstart templates. The Iot Hub template schema can be found here.
There are several methods for deploying a template. You use Azure PowerShell in this tutorial.
To run the PowerShell script, Select Try it to open the Azure Cloud shell. To paste the script, right-click the shell, and then select Paste:
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
$location = Read-Host -Prompt "Enter the location (i.e. 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/101-iothub-with-consumergroup-create/azuredeploy.json" `
-iotHubName $iotHubName
As you can see from the PowerShell script, the template used is from Azure Quickstart templates. To use your own, you need to first upload the template file to the Cloud shell, and then use the -TemplateFile
switch to specify the file name. For an example, see Deploy the template.
Now you have deployed an IoT hub by using an Azure Resource Manager template, you may want to explore further:
- Read about the capabilities of the IoT Hub resource provider REST API.
- Read Azure Resource Manager overview to learn more about the capabilities of Azure Resource Manager.
- For the JSON syntax and properties to use in templates, see Microsoft.Devices resource types.
To learn more about developing for IoT Hub, see the following articles:
To further explore the capabilities of IoT Hub, see: