Delete registered devices with IoT RRS feed

  • Question

  • I want to find out how to delete an IoT Device that has been registered with IoT and IoT Device Provisioning Service.

    The device has been provisioned with IoT DPS (code not shown here), then registered via the code below. The device is deleted from IoT DPS.

        var provisioningClient = ProvisioningDeviceClient.Create(Globals.IotDpsGlobalEndpoint,
                            new SecurityProviderSymmetricKey(Globals.IotDeviceId, DpsSymmKey, DpsSymmKey),
                            new ProvisioningTransportHandlerHttp());
        var regResult = await provisioningClient.RegisterAsync();

    like below:


    i am looking for code sample on how to delete device shown above.                    

    Wednesday, August 14, 2019 9:31 AM


  • For future reference the answer from Joy Wang on StackOverflow:

    You could use the sdk RemoveDeviceAsync(String), try the code below, it works on my side.

    The connection string you can find in your IoT Hub in the portal -> Shared access policies -> click iothubowner.

     public static async Task DeleteDevice()
                var registryManager = RegistryManager.CreateFromConnectionString("HostName=xxxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxxxxxxx");
                await registryManager.RemoveDeviceAsync("<device id>");
            catch (Exception ex)
                Console.WriteLine("Error in sample: {0}", ex.Message);
    <time datetime="2019-08-15T07:25:20" itemprop="dateCreated" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;box-sizing:inherit;"></time>
    answered yesterday
    Joy Wang
    11.8k22 gold badges66 silver badges

    Saturday, August 17, 2019 1:09 AM