How To Create Azure IoT Hub Using PowerShell

Introduction

 
In this article, we are going to see how to create an Azure IoT Hub using Azure PowerShell cmdlets. IoT Hub is used to connect, manage, and monitor billions of IoT devices. It securely connects the devices to develop IoT applications. IoT Hub is a flexible cloud platform service that supports multiple protocols and open-source SDKs.
 
Prerequisite
 
Before you begin to utilize PowerShell to oversee the Azure PowerShell, ensure that the Azure PowerShell has been installed. If not installed, here is an article on How to install the Azure PowerShell module and also Install the Azure IoT module. You need to do this only once for each computer from which you are running Azure PowerShell commands.
 
Connecting to Azure Portal
 
Connect to Azure Portal using Connect-AzureRmAccount cmdlet.
 
Connect-AzureRmAccount
 
Create Azure IoT Hub With PowerShell
 
Creating Azure Resource Group
 
You can create Resource Groups in Azure using New-AzureRmResourceGroup cmdlets. The required parameters are -
  • Name - Specify the name of the resource group.
  • Location - Specify the Azure data center location of the resource group, such as South India or East US.
    1. $ResourceGroupName="MyIOTRG"    
    2. $location="East US"    
    3. New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location  
 Looking at our Azure portal, we can see the new resource group has been created.
 
Create Azure IoT Hub With PowerShell
 
Creating Azure IoT Hub
 
You can create Azure IoT Hub using New-AzureRmIotHub cmdlets. This example creates an S1 hub called "jsiotconnect" in the East US region. The required parameters are -
  • ResourceGroupName - Specify the name of the resource group.
  • Name - Specify the name of the IoT Hub
  • Location - Specify the Azure data center location of the resource group, such as South India and east us.
  • SkuName - Specify the SKU name for the storage account.
     
    1. $IoTHubName="jsiotconnect"  
    2. New-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IoTHubName -SkuName S1 -Units 1 -Location $location  
Create Azure IoT Hub With PowerShell
 
Final Code
  1. Connect-AzureRmAccount    
  2. $ResourceGroupName="MyIOTRG"    
  3. $location="East US"    
  4. New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location    
  5. $IoTHubName="jsiotconnect "    
  6. New-AzureRmIotHub -ResourceGroupName $ResourceGroupName -Name $IoTHubName -SkuName S1 -Units 1 -Location $location   
I hope you have learned how to create an Azure IoT Hub using Azure PowerShell programmatically. Feel free to fill up the comment box below if you need any assistance.