Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register a new Azure IoT Device
Import-Module AzureIoT
Import-Module AzureRM
Login-AzureRmAccount
# 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).azure-devices.net;SharedAccessKeyName=$($IoTKeyName);SharedAccessKey=$($IoTHubKey.PrimaryKey)"
# New DeviceID
$newDeviceID = "ESP8266_12345"
$deviceParams = @{
iotConnString = $IoTConnectionString
deviceId = $newDeviceID
}
$device = Register-IoTDevice @deviceParams
$device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment