Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Register a new Azure IoT Device
Import-Module AzureIoT
Import-Module AzureRM
# Create New IoT Device
# IoT Hub RG & Location
$RGName = "MyMongooseIoTHub"
$location = "East US"
# IoT Hub
$IoTHubName = "MyMongooseIoTHub"
$IoTKeyName = "iothubowner"
$IoTHub = Get-AzureRmIotHub -Name $IoTHubName -ResourceGroupName $RGName
$IoTHubKey = Get-AzureRmIotHubKey -ResourceGroupName $iothub.Resourcegroup -Name $IoTHubName -KeyName $IoTKeyName
# IoT ConnectionString
$IoTConnectionString = "HostName=$($IoTHubName);SharedAccessKeyName=$($IoTKeyName);SharedAccessKey=$($IoTHubKey.PrimaryKey)"
# New DeviceID
$newDeviceID = "ESP8266_12345"
$deviceParams = @{
iotConnString = $IoTConnectionString
deviceId = $newDeviceID
$device = Register-IoTDevice @deviceParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.