Search code examples
azurepowershellazure-functionsazure-iot-sdkazure-sdk

IotHub Devices created via PowerShell not displaying


I'm creating Azure Iot hub devices both on the portal and via powershell. The devices created on the portal are displayed in the list of devices of the Iot hub,

but the devices created by Powershell's

Add-AzIotHubDevice -ResourceGroupName $resourceGroupName -IotHubName $iothubName -DeviceId $id -AuthMethod "shared_private_key" -EdgeEnabled

are not displayed on the portal although I can't create a device with Id used by powershell.

I tried to log out and then log in - no luck.

It looks like the devices created by Powershell cmdlet are "somewhere" because Id's are busy.


Solution

  • To achieve the requirement we have tried the same to create a new IotHub and adding a device to it using Powershell --version 7.2.1 .

    The cmdlet you are using which will Create an edge enabled IoT device with default authorization (shared private key).

    Steps we followed :

    New-AzIotHub ` -ResourceGroupName rgname -Name IotHubname -SkuName S1 -Units 1 -Location "west us2"

    enter image description here

    enter image description here

    NOTE:- Make sure that you have provided th same location based on your resource group location.

    • Trying to add a new device using the same command that you are using .

      Add-AzIotHubDevice -ResourceGroupName "RG NAME" -IotHubName "IOTHUB NAME" -DeviceId "myDevice3" -AuthMethod "shared_private_key" -EdgeEnabled

    enter image description here

    • Navigate to Azure Portal> IotHub>Iotedge after sometime make a reload and check the device which we have created using powershell.

    enter image description here

    For more information please refer this Microsoft Documentation:- Add-AzIotHubDevice