Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 4.15 KB

iot-hub-rm-template-powershell.md

File metadata and controls

76 lines (53 loc) · 4.15 KB

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

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

[!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.

Create an IoT hub

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.

Next steps

Now you have deployed an IoT hub by using an Azure Resource Manager template, you may want to explore further:

To learn more about developing for IoT Hub, see the following articles:

To further explore the capabilities of IoT Hub, see: