az iot hub

Manage entities in an Azure IoT Hub.

Commands

az iot hub apply-configuration Apply a deployment manifest to a single device.
az iot hub configuration Manage IoT device configurations at scale.
az iot hub configuration create Create an IoT device configuration in the target IoT Hub.
az iot hub configuration delete Delete an IoT device configuration.
az iot hub configuration list List IoT device configurations in an IoT Hub.
az iot hub configuration show Get the details of an IoT device configuration.
az iot hub configuration show-metric Evaluate a target user or system metric defined in an IoT device configuration.
az iot hub configuration update Update an IoT device configuration with the specified properties.
az iot hub device-identity Manage IoT devices.
az iot hub device-identity add-children Add specified comma-separated list of non edge device ids as children of specified edge device.
az iot hub device-identity create Create a device in an IoT Hub.
az iot hub device-identity delete Delete an IoT Hub device.
az iot hub device-identity export Export all device identities from an IoT Hub to an Azure Storage blob container.
az iot hub device-identity get-parent Get the parent device of the specified device.
az iot hub device-identity import Import device identities to an IoT Hub from a blob.
az iot hub device-identity list List devices in an IoT Hub.
az iot hub device-identity list-children Print comma-separated list of assigned child devices.
az iot hub device-identity remove-children Remove non edge devices as children from specified edge device.
az iot hub device-identity set-parent Set the parent device of the specified non-edge device.
az iot hub device-identity show Get the details of an IoT Hub device.
az iot hub device-identity show-connection-string Show a given IoT Hub device connection string.
az iot hub device-identity update Update an IoT Hub device.
az iot hub device-twin Manage IoT device twin configuration.
az iot hub device-twin replace Replace device twin definition with target json.
az iot hub device-twin show Get a device twin definition.
az iot hub device-twin update Update device twin definition.
az iot hub generate-sas-token Generate a SAS token for a target IoT Hub or device.
az iot hub invoke-device-method Invoke a device method.
az iot hub invoke-module-method Invoke an Edge module method.
az iot hub module-identity Manage IoT device modules.
az iot hub module-identity create Create a module on a target IoT device in an IoT Hub.
az iot hub module-identity delete Delete a device in an IoT Hub.
az iot hub module-identity list List modules located on an IoT device in an IoT Hub.
az iot hub module-identity show Get the details of an IoT device module in an IoT Hub.
az iot hub module-identity show-connection-string Show a target IoT device module connection string.
az iot hub module-identity update Update an IoT Hub device module.
az iot hub module-twin Manage IoT device module twin configuration.
az iot hub module-twin replace Replace a module twin definition with target json.
az iot hub module-twin show Show a module twin definition.
az iot hub module-twin update Update module twin definition.
az iot hub monitor-events Monitor device telemetry & messages sent to an IoT Hub.
az iot hub monitor-feedback Monitor feedback sent by devices to acknowledge cloud-to-device (C2D) messages.
az iot hub query Query an IoT Hub using a powerful SQL-like language.

az iot hub apply-configuration

Apply a deployment manifest to a single device.

az iot hub apply-configuration --content
--device-id
[--hub-name]
[--login]
[--resource-group]

Examples

Test modules while in development.

az iot hub apply-configuration --hub-name {iothub_name} --device-id {device_id} --content ../mycontent.json

Required Parameters

--content -k

Configuration content. Provide file path or raw json.

--device-id -d

Target Device.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--resource-group -g

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

az iot hub generate-sas-token

Generate a SAS token for a target IoT Hub or device.

az iot hub generate-sas-token [--device-id]
[--du]
[--hub-name]
[--key-type {primary, secondary}]
[--login]
[--module-id]
[--pn]
[--resource-group]

Examples

Generate an IoT Hub SAS token using the iothubowner policy and primary key.

az iot hub generate-sas-token -n {iothub_name}

Generate an IoT Hub SAS token using the registryRead policy and secondary key.

az iot hub generate-sas-token -n {iothub_name} --policy registryRead --key-type secondary

Generate a device SAS token using the iothubowner policy to access the {iothub_name} device registry.

az iot hub generate-sas-token -d {device_id} -n {iothub_name}

Generate a device SAS token using an IoT Hub connection string (with registry access)

az iot hub generate-sas-token -d {device_id} --login 'HostName=myhub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=12345'

Optional Parameters

--device-id -d

Target Device.

--du --duration

Valid token duration in seconds.

default value: 3600
--hub-name -n

IoT Hub name.

--key-type --kt

Shared access policy key type for auth.

accepted values: primary, secondary
default value: primary
--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--module-id -m

Target Module.

--pn --policy-name

Shared access policy with operation permissions for target IoT Hub entity.

default value: iothubowner
--resource-group -g

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

az iot hub invoke-device-method

Invoke a device method.

az iot hub invoke-device-method --device-id
--method-name
[--hub-name]
[--login]
[--method-payload]
[--resource-group]
[--timeout]

Required Parameters

--device-id -d

Target Device.

--method-name --mn

Target method for invocation.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--method-payload --mp

Json payload to be passed to method. Must be file path or raw json.

default value: {}
--resource-group -g

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

--timeout --to

Maximum number of seconds to wait for method result.

default value: 60

az iot hub invoke-module-method

Invoke an Edge module method.

az iot hub invoke-module-method --device-id
--method-name
--module-id
[--hub-name]
[--login]
[--method-payload]
[--resource-group]
[--timeout]

Required Parameters

--device-id -d

Target Device.

--method-name --mn

Target method for invocation.

--module-id -m

Target Module.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--method-payload --mp

Json payload to be passed to method. Must be file path or raw json.

default value: {}
--resource-group -g

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

--timeout --to

Maximum number of seconds to wait for method result.

default value: 60

az iot hub monitor-events

Monitor device telemetry & messages sent to an IoT Hub.

az iot hub monitor-events [--cg]
[--content-type]
[--device-id]
[--device-query]
[--enqueued-time]
[--hub-name]
[--login]
[--properties {all, anno, app, sys}]
[--repair {false, true}]
[--resource-group]
[--timeout]
[--yes {false, true}]

Examples

Basic usage

az iot hub monitor-events -n {iothub_name}

Basic usage with an IoT Hub connection string

az iot hub monitor-events -n {iothub_name} --login 'HostName=myhub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=12345'

Basic usage when filtering on target device

az iot hub monitor-events -n {iothub_name} -d {device_id}

Basic usage when filtering targeted devices with a wildcard in the ID

az iot hub monitor-events -n {iothub_name} -d Device*

Filter devices using IoT Hub query language

az iot hub monitor-events -n {iothub_name} -q "select * from devices where tags.location.region = 'US'"

Filter device and specify an Event Hub consumer group to bind to.

az iot hub monitor-events -n {iothub_name} -d {device_id} --cg {consumer_group_name}

Receive message annotations (message headers)

az iot hub monitor-events -n {iothub_name} -d {device_id} --properties anno

Receive message annotations + system properties. Never time out.

az iot hub monitor-events -n {iothub_name} -d {device_id} --properties anno sys --timeout 0

Receive all message attributes from all device messages

az iot hub monitor-events -n {iothub_name} --props all

Receive all messages and parse message payload as JSON

az iot hub monitor-events -n {iothub_name} --content-type application/json

Optional Parameters

--cg --consumer-group -c

Specify the consumer group to use when connecting to event hub endpoint.

default value: $Default
--content-type --ct

Specify the Content-Type of the message payload to automatically format the output to that type.

--device-id -d

Target Device.

--device-query -q

Specify a custom query to filter devices.

--enqueued-time --et -e

Indicates the time that should be used as a starting point to read messages from the partitions. Units are milliseconds since unix epoch. If no time is indicated "now" is used.

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--properties --props -p

Indicate key message properties to output. sys = system properties, app = application properties, anno = annotations.

accepted values: all, anno, app, sys
--repair -r

Reinstall uamqp dependency compatible with extension version. Default: false.

accepted values: false, true
--resource-group -g

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

--timeout --to -t

Maximum seconds to maintain connection without receiving message. Use 0 for infinity.

default value: 300
--yes -y

Skip user prompts. Indicates acceptance of dependency installation (if required). Used primarily for automation scenarios. Default: false.

accepted values: false, true

az iot hub monitor-feedback

Monitor feedback sent by devices to acknowledge cloud-to-device (C2D) messages.

az iot hub monitor-feedback [--device-id]
[--hub-name]
[--login]
[--repair {false, true}]
[--resource-group]
[--wait-on-msg]
[--yes {false, true}]

Examples

Basic usage

az iot hub monitor-feedback -n {iothub_name}

Basic usage with an IoT Hub connection string

az iot hub monitor-feedback -n {iothub_name} --login 'HostName=myhub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=12345'

Basic usage when filtering on target device

az iot hub monitor-feedback -n {iothub_name} -d {device_id}

Exit feedback monitor upon receiving a message with specific id (uuid)

az iot hub monitor-feedback -n {iothub_name} -d {device_id} -w {message_id}

Optional Parameters

--device-id -d

Target Device.

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--repair -r

Reinstall uamqp dependency compatible with extension version. Default: false.

accepted values: false, true
--resource-group -g

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

--wait-on-msg -w

Feedback monitor will block until a message with specific id (uuid) is received.

--yes -y

Skip user prompts. Indicates acceptance of dependency installation (if required). Used primarily for automation scenarios. Default: false.

accepted values: false, true

az iot hub query

Query an IoT Hub using a powerful SQL-like language.

az iot hub query --query-command
[--hub-name]
[--login]
[--resource-group]
[--top]

Examples

Query all device twin data in an Azure IoT Hub.

az iot hub query -n {iothub_name} -q "select * from devices"

Query all module twin data on target device.

az iot hub query -n {iothub_name} -q "select * from devices.modules where devices.deviceId = '{device_id}'"

Required Parameters

--query-command -q

User query to be executed.

Optional Parameters

--hub-name -n

IoT Hub name.

--login -l

This command supports an entity connection string with rights to perform action. Use to avoid session login via "az login". If both an entity connection string and name are provided the connection string takes priority.

--resource-group -g

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

--top

Maximum number of elements to return. By default query has no cap.