IoT devices - az iot device

Manage devices in your Azure IoT hub.

These commands are in preview.

Commands

az iot device create Register a device in an IoT Hub.
az iot device delete Delete a device from an IoT Hub.
az iot device export Export all the device identities in the IoT hub identity registry to an Azure Storage blob container.
az iot device import Import, update, or delete device identities in the IoT hub identity registry from a blob.
az iot device list List devices in an IoT Hub.
az iot device message Manage IoT device messaging.
az iot device message abandon Abandon a cloud-to-device message.
az iot device message complete Complete a cloud-to-device message.
az iot device message receive Receive a cloud-to-device message.
az iot device message reject Reject a cloud-to-device message.
az iot device message send Send a device-to-cloud message.
az iot device show Show metadata of a device in an IoT Hub.
az iot device show-connection-string Show the connection string of devices in an IoT Hub.
az iot device update Update metadata of a device in an IoT Hub.

az iot device create

Register a device in an IoT Hub.

az iot device create --device-id
--hub-name
[--output-dir]
[--primary-thumbprint]
[--resource-group]
[--secondary-thumbprint]
[--valid-days]
[--x509]

Examples

Create a device authenticating with symmetric key.

az iot device create --hub-name MyIotHub --device-id MyDevice

Create a device authenticating with existing X.509 certificate.

az iot device create --hub-name MyIotHub --device-id MyDevice --x509 --primary-thumbprint X.509_certificate_thumbprint

Create a device authenticating with self-signed X.509 certificate, which is put into to the current directory.

az iot device create --hub-name MyIotHub --device-id MyDevice --x509

Create a device authenticating with self-signed X.509 certificate, which is valid for 100 days.

az iot device create --hub-name MyIotHub --device-id MyDevice --x509 --valid-days 100

Create a device authenticating with self-signed X.509 certificate, which is put into the specified directory.

az iot device create --hub-name MyIotHub --device-id MyDevice --x509 --output-dir /path/to/output

Required Parameters

--device-id -d

Device Id.

--hub-name

IoT Hub name.

Optional Parameters

--output-dir

Output directory for generated self-signed X.509 certificate. Default is current working directory.

--primary-thumbprint

Primary X.509 certificate thumbprint to authenticate device.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

--secondary-thumbprint

Secondary X.509 certificate thumbprint to authenticate device.

--valid-days

Number of days the generated self-signed X.509 certificate should be valid for. Default validity is 365 days.

--x509

Use X.509 certificate for device authentication.

az iot device delete

Delete a device from an IoT Hub.

az iot device delete --device-id
--hub-name
[--etag]
[--resource-group]

Required Parameters

--device-id -d

Device Id.

--hub-name

IoT Hub name.

Optional Parameters

--etag

ETag of the target device. It is used for the purpose of optimistic concurrency. Delete operation will be performed only if the specified ETag matches the value maintained by the server, indicating that the device identity has not been modified since it was retrieved. Default value is set to wildcard character (*) to force an unconditional delete.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

az iot device export

For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities.

az iot device export --blob-container-uri
--hub-name
[--include-keys]
[--resource-group]

Required Parameters

--blob-container-uri

Blob Shared Access Signature URI with write access to a blob container.This is used to output the status of the job and the results.

--hub-name

IoT Hub name.

Optional Parameters

--include-keys

If set, keys are exported normally. Otherwise, keys are set to null in export output.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

az iot device import

For more information, see https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-identity-registry#import-and-export-device-identities.

az iot device import --hub-name
--input-blob-container-uri
--output-blob-container-uri
[--resource-group]

Required Parameters

--hub-name

IoT Hub name.

--input-blob-container-uri

Blob Shared Access Signature URI with read access to a blob container.This blob contains the operations to be performed on the identity registry.

--output-blob-container-uri

Blob Shared Access Signature URI with write access to a blob container.This is used to output the status of the job and the results.

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

az iot device list

List devices in an IoT Hub.

az iot device list --hub-name
[--resource-group]
[--top]

Required Parameters

--hub-name

IoT Hub name.

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

--top

Maximum number of device identities to return.

default value: 20

az iot device show

Show metadata of a device in an IoT Hub.

az iot device show --device-id
--hub-name
[--resource-group]

Required Parameters

--device-id -d

Device Id.

--hub-name

IoT Hub name.

Optional Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

az iot device show-connection-string

If the device identifier is not provided, connection strings for all devices in your IoT Hub are returned. Otherwise, the connection string of the target device is returned.

az iot device show-connection-string --hub-name
[--device-id]
[--key {primary, secondary}]
[--resource-group]
[--top]

Examples

Show the connection string of a device in an IoT Hub using primary key.

az iot device show-connection-string --hub-name MyIotHub --device-id MyDevice

Show the connection string of a device in an IoT Hub using secondary key.

az iot device show-connection-string --hub-name MyIotHub --device-id MyDevice --key secondary

Show the connection strings of the default devices in an IoT Hub using primary key.

az iot device show-connection-string --hub-name MyIotHub

Show the connection strings of the top 100 devices in an IoT Hub using primary key.

az iot device show-connection-string --hub-name MyIotHub --top 100

Required Parameters

--hub-name

IoT Hub name.

Optional Parameters

--device-id -d

Device Id.

--key

The key to use.

accepted values: primary, secondary
default value: primary
--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

--top

Maximum number of connection strings to return.

default value: 20

az iot device update

Update metadata of a device in an IoT Hub.

az iot device update --device-id
--hub-name
[--add]
[--remove]
[--resource-group]
[--set]

Examples

Disable a device.

az iot device update --hub-name MyIotHub --device-id MyDevice --set status=disabled

Required Parameters

--device-id -d

Device Id.

--hub-name

IoT Hub name.

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty .

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=.

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.