
In this Azure tutorial, we will discuss How To Create Azure IoT Hub Using PowerShell, Along with this, we will also discuss a few other topics like below
- What is Azure IoT hub?
- Create an IoT hub using the New-AzIotHub cmdlet
- How To Delete IoT Hub In Azure PowerShell
- How To Create an IoT hub using the Azure CLI
- Create an IoT hub using the Azure CLI
- How To Delete IoT Hub Using Azure CLI
- How To Create Azure IoT Hub Using Azure Portal
- How To Delete IoT Hub Using Azure Portal
Table of Contents
- How To Create Azure IoT Hub Using PowerShell
- What is Azure IoT hub?
- Create an IoT hub using the New-AzIotHub cmdlet
- Prerequisites
- Connect to your Azure subscription
- Create a resource group
- Create an Azure IoT hub
- Final Code
- How To Delete IoT Hub In Azure PowerShell
- How To Create an IoT hub using the Azure CLI
- Prerequisites
- Create an IoT hub using the Azure CLI
- Create a resource group Azure CLI
- How To Delete IoT Hub Using Azure CLI
- How To Create Azure IoT Hub Using Azure Portal
- How To Delete IoT Hub Using Azure Portal
- Wrapping Up
How To Create Azure IoT Hub Using PowerShell
Well, Let’s discuss an excellent topic i.e How To Create Azure IoT Hub Using PowerShell cmdlets. Before starting the actual topic, let’s discuss a bit about what is azure IoT hub? and the Prerequisites needed here to Create Azure IoT Hub Using PowerShell.
What is Azure IoT hub?
Azure IoT Hub is a Cloud-hosted solution that actually helps to communicate with your IoT application and different devices it manages or it connects the devices to develop different IoT applications. It also provides different excellent features like per-device authentication, built-in device management, etc.
Create an IoT hub using the New-AzIotHub cmdlet
Hope you got some idea on Azure IoT hub by now. Let’s discuss the Prerequisites needed to Create Azure IoT Hub Using PowerShell.
Prerequisites
You must install Azure PowerShell on your machine. If you have not installed Azure PowerShell till now. Install the Azure PowerShell in your machine now.
Connect to your Azure subscription
In order to work with the Azure PowerShell to create the Azure IoT Hub, we need to connect to the Azure Subscription, You can use the below PowerShell cmdlet for Connecting to Azure Portal.
PS C:\WINDOWS\system32> Login-AzAccount
Once you will execute the above PowerShell cmdlet, it will prompt you to enter your Azure credential details to login.

The next step is to Creating Azure Resource Group.
Create a resource group
You need to use the below PowerShell cmdlet to create a resource group in Azure. A resource group is a very important component here that is much needed to deploy the IoT hub.
You can either use your existing resource group here or you can create a new resource group. if you don’t have an existing resource group, you can use the New-AzResourceGroup PowerShell cmdlet to create a new Azure Resource Group.
PS C:\WINDOWS\system32> New-AzResourceGroup -Name Demo345 -Location "East US"
Here, the Azure Resource Group name is Demo345 and the location is East US. You can able to see that the Azure Resource Group is created successfully without any issue.

If we will log in to the Azure Portal to check if the Azure Resource Group is created successfully, you can see below the new resource group has been created successfully without any issue.

The next step is to create the Creating Azure IoT Hub.
Create an Azure IoT hub
You can use the New-AzIotHub PowerShell cmdlet to create an Azure IoT hub. Here we will create an S1 IoT Hub named the TSInfoIoTHub which will be located in the East US region.
Here we need to provide few parameters along with the New-AzIotHub PowerShell cmdlet.
- ResourceGroupName: we need to provide the name of the resource group that we have created above or you can also provide the name of any existing resource group name if you have.
- Name: Provide a unique name for the Azure IoTHub.
- Location: You must specify the location of the Resource Group i.e nothing but the Azure data center location of your resource group.
- SkuName: Another important parameter is the SkuName for the storage account that you have to provide along with the New-AzIotHub PowerShell cmdlet.
New-AzIotHub -ResourceGroupName Demo345 -Name TSInfoIoTHub -SkuName S1 -Units 1 -Location "East US"
Once we have executed the above PowerShell cmdlet, you can able to see the query executed successfully and the IoTHub created successfully without any issue.

Now, to make sure that it has been created successfully, Let’s log in to the Azure Portal and see if the IoTHub is available there.

Final Code
The complete code looks like below
Login-AzAccount
$ResourceGroupName="Demo345"
$location="East US"
New-AzResourceGroup -Name $ResourceGroupName -Location $location
$IoTHubName="TSInfoIoTHub"
New-AzIotHub -ResourceGroupName $ResourceGroupName -Name $IoTHubName -SkuName S1 -Units 1 -Location $location
This is how to create Azure IoT Hub using PowerShell.
How To Delete IoT Hub In Azure PowerShell
So we have created the Azure IoT Hub using PowerShell. Now if you want to remove the Azure IoT Hub, you need to follow the below PowerShell cmdlet
Remove-AzIotHub -ResourceGroupName Demo345 -Name TSInfoIoTHub
Once we have executed the above PowerShell cmdlet, you can able to see the Azure IoT Hub has been deleted successfully with out any issue

Or, you can also delete the resource group using the below PowerShell cmdlet which will anyway delete the Azure IoTHub.
Remove-AzResourceGroup -Name Demo345
How To Create an IoT hub using the Azure CLI
Well, we have discussed above how to create Azure IoT Hub using PowerShell. Now the time to discuss how to create an IoT hub using the Azure CLI. Before starting the actual topic, let’s discuss the Prerequisites needed to Create an IoT hub using the Azure CLI.
Prerequisites
- You must install the Azure CLI. If you have not installed the Azure CLI till now, Install the Azure CLI now.
- Install the Azure CLI extensions along with the Azure CLI.
- You need to upgrade to the latest version by running the az upgrade cmdlet.
Create an IoT hub using the Azure CLI
Follow the below steps to Create an IoT hub using the Azure CLI.
Create a resource group Azure CLI
The first and important step is to create a resource group using Azure CLI. Either you can use your existing Resource Group or if you don’t have then create a Resource Group using Azure CLI. You can use the below command to create the Resource group.
az group create --name {your resource group name} --location westus
az group create --name Demo478 --location westus
Now the next step is to Create a resource group Azure CLI using the below command
az iot hub create --name {your iot hub name} \
--resource-group {your resource group name} --sku S1
az iot hub create --name TsinfoIoTHub \
--resource-group Demo478 --sku S1
This is how to create an IoT hub using the Azure CLI. You can refer to the above Instruction.
How To Delete IoT Hub Using Azure CLI
Well, we have created an IoT hub using the Azure CLI. Now if you want to remove the Azure IoTHub, you can use the below command to remove an IoT Hub.
az iot hub delete --name TsinfoIoTHub -\
-resource-group Demo478
Or, you can also use the below command to remove the Azure Resource group using Azure CLI.
az group delete --name Demo478
How To Create Azure IoT Hub Using Azure Portal
Above, we have discussed How To Create Azure IoT Hub Using PowerShell and we have also discussed How To Create an IoT hub using the Azure CLI. Now, let’s discuss How To Create Azure IoT Hub Using Azure Portal.
Follow the below steps to Create Azure IoT Hub Using Azure Portal.
Step-1: Login to the Azure Portal (https://portal.azure.com/)
Step-2: Once, you have logged in to the Azure Portal, search for the IoT Hub on the main search bar as shown below and click on the search result IoT Hub under services.

Step-3: On the IoT Hub page, click on the + Add button to create the Azure IoT Hub.

Now Provide the below details on the next page as shown below
- Subscription: You need to choose the correct subscription that you want to use here to create the Azure IoT Hub.
- Resource group: Select your existing resource group or if you don’t have any resource group created, you can click on the Create new link to create a new resource group as highlighted below.
- Region: Select the Region for the Resource Group.
- IoT hub name: You must provide a unique name for your Azure IoT Hub that you want to create.
Finally, click on the Review + Create button.

Now, you can validate all the details and click on the Create button to create the Azure IoT Hub.

Now, you can able to see that the deployment is successfully completed without any issue as shown below. Click on the Go to resource button to navigate to the IoT Hub that you have created just now.

This is How To Create Azure IoT Hub Using Azure Portal.
How To Delete IoT Hub Using Azure Portal
If you want to delete the Azure IoT Hub using the Azure Portal, then navigate to the Azure IoT Hub that we have created using the above steps. Now click on the Delete button to delete the Azure IoT Hub in the Azure Portal as highlighted below.

Then, type the name of your Azure IoT Hub to confirm the deletion, and finally, click on the Delete button to delete the Azure IoT Hub as shown below.

You may also like following the below articles
- What Is the Difference Between Azure and Office 365?
- The Specified Module ‘AzureRM’ Was Not Loaded
- How To Convert Text To Speech With Azure Cognitive Services
- The Term ‘Connect-AzureRmAccount’ is Not Recognized
- Azure Cognitive Services Modules For Python
- How To Create Azure Windows Virtual Machine From A Snapshot PowerShell
Wrapping Up
Well, in this article, we have discussed How To Create Azure IoT Hub Using PowerShell, What is Azure IoT hub?, Create an IoT hub using the New-AzIotHub cmdlet and we have also discussed Create an IoT hub using the New-AzIotHub cmdlet, How To Delete IoT Hub In Azure PowerShell, How To Create an IoT hub using the Azure CLI, Create an IoT hub using the Azure CLI, How To Delete IoT Hub Using Azure CLI, How To Create Azure IoT Hub Using Azure Portal and How To Delete IoT Hub Using Azure Portal.