Create an IoT hub using the New-AzureRmIotHub cmdlet

Introduction

You can use Azure PowerShell cmdlets to create and manage Azure IoT hubs. This tutorial shows you how to create an IoT hub with PowerShell.

To complete this how-to, you need an Azure subscription. If you don't have an Azure subscription, create a free account before you begin.

Open Azure Cloud Shell

Azure Cloud Shell is a free, interactive shell that you can use to run the steps in this article. Common Azure tools are preinstalled and configured in Cloud Shell for you to use with your account. Just select the Copy button to copy the code, paste it in Cloud Shell, and then press Enter to run it. There are a few ways to open Cloud Shell:

Select Try It in the upper-right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser. https://shell.azure.com/bash
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell in the portal

Connect to your Azure subscription

If you are using the Cloud Shell, you are already logged in to your subscription. If you are running PowerShell locally instead, enter the following command to sign in to your Azure subscription:

# Log into Azure account.
Login-AzureRMAccount

Create a resource group

You need a resource group to deploy an IoT hub. You can use an existing resource group or create a new one.

To create a resource group for your IoT hub, use the New-AzureRmResourceGroup command. This example creates a resource group called MyIoTRG1 in the East US region:

New-AzureRmResourceGroup -Name MyIoTRG1 -Location "East US"

Create an IoT hub

To create an IoT hub in the resource group you created in the previous step, use the New-AzureRmIotHub command. This example creates an S1 hub called MyTestIoTHub in the East US region:

New-AzureRmIotHub `
    -ResourceGroupName MyIoTRG1 `
    -Name MyTestIoTHub `
    -SkuName S1 -Units 1 `
    -Location "East US"

The name of the IoT hub must be globally unique.

Important

The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.

You can list all the IoT hubs in your subscription using the Get-AzureRmIotHub command:

Get-AzureRmIotHub

This example shows the S1 Standard IoT Hub you created in the previous step.

You can delete the IoT hub using the Remove-AzureRmIotHub command:

Remove-AzureRmIotHub `
    -ResourceGroupName MyIoTRG1 `
    -Name MyTestIoTHub

Alternatively, you can remove a resource group and all the resources it contains using the Remove-AzureRmResourceGroup command:

Remove-AzureRmResourceGroup -Name MyIoTRG1

Next steps

Now you have deployed an IoT hub using a PowerShell cmdlet, if you want to explore further, check out the following articles:

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

To further explore the capabilities of IoT Hub, see: