az iot device

(PREVIEW) Manage devices in your Azure IoT hub.

Commands

az iot device create Register a device for 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 (PREVIEW) 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 Get the details for a device in an IoT hub.
az iot device show-connection-string Show the connection strings for devices in an IoT hub.
az iot device update Update the metadata of a device in an IoT hub.

az iot device create

Register a device for an IoT hub.

This command is deprecating. Use 'az iot hub device-identity create' via the IoT Extension instead.

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 an 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 a 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 a self-signed X.509 certificate that is valid for 100 days.

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

Create a device authenticating with a self-signed X.509 certificate, and write the certificate to /path/to/output.

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=<name>.

--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.

This command is deprecating. Use 'az iot hub device-identity delete' via the IoT Extension instead.

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=<name>.

az iot device export

Export all the device identities in the IoT hub identity registry to an Azure Storage blob container.

This command is deprecating. Use 'az iot hub device-identity export' via the IoT Extension instead. 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=<name>.

az iot device import

Import, update, or delete device identities in the IoT hub identity registry from a blob.

This command is deprecating. Use 'az iot hub device-identity import' via the IoT Extension instead. 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=<name>.

az iot device list

List devices in an IoT hub.

This command is deprecating. Use 'az iot hub device-identity list' via the IoT Extension instead.

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=<name>.

--top

Maximum number of device identities to return.

default value: 20

az iot device show

Get the details for a device in an IoT hub.

This command is deprecating. Use 'az iot hub device-identity show' via the IoT Extension instead.

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=<name>.

az iot device show-connection-string

Show the connection strings for devices in an IoT hub.

This command is deprecating. Use 'az iot hub device-identity show-connection-string' via the IoT Extension instead.

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 the 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 the 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=<name>.

--top

Maximum number of connection strings to return.

default value: 20

az iot device update

Update the metadata of a device in an IoT hub.

This command is deprecating. Use 'az iot hub device-identity update' via the IoT Extension instead.

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 <key=value, string or JSON string>.

--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=<name>.

--set

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