Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created February 1, 2018 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/5792fe0907181ad0eeb6eb3a7b9cbd5b to your computer and use it in GitHub Desktop.
Save darrenjrobinson/5792fe0907181ad0eeb6eb3a7b9cbd5b to your computer and use it in GitHub Desktop.
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