Create an IoT hub using the New-AzIotHub cmdlet
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.
We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Alternatively, you can use Azure Cloud Shell, if you'd rather not install additional modules onto your machine. The following section gets you started with Azure Cloud Shell.
Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
|Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell.|
|Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.|
|Select the Cloud Shell button on the menu bar at the upper right in the Azure portal.|
To use Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block (or command block) to copy the code or command.
Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
Select Enter to run the code or command.
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 new resource group for your IoT hub, use the New-AzResourceGroup command. This example creates a resource group called MyIoTRG1 in the East US region:
New-AzResourceGroup -Name MyIoTRG1 -Location "East US"
Connect to your Azure subscription
If you're using Cloud Shell, you're already logged in to your subscription, so you can skip this section. If you're running PowerShell locally instead, enter the following command to sign in to your Azure subscription:
# Log into Azure account. Login-AzAccount
Create an IoT hub
Create an IoT hub using your resource group. Use the New-AzIotHub command. This example creates an S1 hub called MyTestIoTHub in the East US region:
New-AzIotHub ` -ResourceGroupName MyIoTRG1 ` -Name MyTestIoTHub ` -SkuName S1 -Units 1 ` -Location "East US"
The name of the IoT hub must be globally unique.
Because the IoT hub will be publicly discoverable as a DNS endpoint, be sure to avoid entering any sensitive or personally identifiable information when you name it.
To list all the IoT hubs in your subscription, use the Get-AzIotHub command.
This example shows the S1 Standard IoT Hub you created in the previous step.
To delete the IoT hub, use the Remove-AzIotHub command.
Remove-AzIotHub ` -ResourceGroupName MyIoTRG1 ` -Name MyTestIoTHub
Update the IoT hub
You can change the settings of an existing IoT hub after it's created. Here are some properties you can set for an IoT hub:
Pricing and scale: Migrate to a different tier or set the number of IoT Hub units.
IP Filter: Specify a range of IP addresses that will be accepted or rejected by the IoT hub.
Properties: A list of properties that you can copy and use elsewhere, such as the resource ID, resource group, location, and so on.
Explore the Set-AzIotHub commands for a complete list of update options.
Now that you've deployed an IoT hub using a PowerShell cmdlet, explore more articles:
Develop for IoT Hub:
Explore the capabilities of IoT Hub: