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.

Note

Azure has two different deployment models for creating and working with resources: Azure Resource Manager and classic. This article covers using the Azure Resource Manager deployment model.

To complete this tutorial, you need the following:

Connect to your Azure subscription

In a PowerShell command prompt, enter the following command to sign in to your Azure subscription:

Login-AzureRmAccount

If you have multiple Azure subscriptions, signing in to Azure grants you access to all the Azure subscriptions associated with your credentials. Use the following command to list the Azure subscriptions available for you to use:

Get-AzureRMSubscription

Use the following command to select subscription that you want to use to run the commands to create your IoT hub. You can use either the subscription name or ID from the output of the previous command:

Select-AzureRMSubscription `
    -SubscriptionName "{your subscription name}"

Create resource group

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

You can use the following command to discover the locations where you can deploy an IoT hub:

((Get-AzureRmResourceProvider `
  -ProviderNamespace Microsoft.Devices).ResourceTypes `
  | Where-Object ResourceTypeName -eq IoTHubs).Locations

To create a resource group for your IoT hub in one of the supported locations for IoT Hub, use the following 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 following 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"

Note that the name of the IoT hub must be 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 following command:

Get-AzureRmIotHub

The previous example adds an S1 Standard IoT Hub for which you are billed. You can delete the IoT hub using the following command:

Remove-AzureRmIotHub `
    -ResourceGroupName MyIoTRG1 `
    -Name MyTestIoTHub

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

Remove-AzureRmResourceGroup -Name MyIoTRG1

Next steps

Now you have deployed an IoT hub using a PowerShell cmdlet, 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: