az iot hub

Manage entities in an Azure IoT Hub.

Commands

az iot hub configuration

Manage IoT automatic device management configuration at scale.

az iot hub configuration create

Create an IoT automatic device management configuration in a target IoT Hub.

az iot hub configuration delete

Delete an IoT device configuration.

az iot hub configuration list

List IoT automatic device management configurations in an IoT Hub.

az iot hub configuration show

Get the details of an IoT automatic device management 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 specified properties of an IoT automatic device management configuration.

Use --set followed by property assignments for updating a configuration.

Note: Configuration content is immutable. Configuration properties that can be updated are 'labels', 'metrics', 'priority' and 'targetCondition'.

az iot hub connection-string

Manage IoT Hub connection strings.

az iot hub connection-string show

Show the connection strings for an IoT Hub.

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 connection-string

Manage IoT device's connection string.

az iot hub device-identity connection-string show

Show a given IoT Hub device connection string.

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. For inline blob container SAS uri input, please review the input rules of your environment.

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. For inline blob container SAS uri input, please review the input rules of your environment.

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 desired properties and tags.

az iot hub distributed-tracing

Manage distributed settings per-device.

az iot hub distributed-tracing show

Get the distributed tracing settings for a device.

az iot hub distributed-tracing update

Update the distributed tracing options for a device.

az iot hub generate-sas-token

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

az iot hub invoke-device-method

Invoke a device method.

az iot hub invoke-module-method

Invoke an Edge module method.

az iot hub job

Manage IoT Hub jobs (v2).

az iot hub job cancel

Cancel an IoT Hub job.

az iot hub job create

Create and schedule an IoT Hub job for execution.

az iot hub job list

List the historical jobs of an IoT Hub.

az iot hub job show

Show details of an existing IoT Hub job.

az iot hub module-identity

Manage IoT device modules.

az iot hub module-identity connection-string

Manage IoT device module's connection string.

az iot hub module-identity connection-string show

Show a target IoT device module connection string.

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 desired properties and tags.

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 generate-sas-token

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

For device SAS tokens, the policy parameter is used to access the the device registry only. Therefore the policy should have read access to the registry. For IoT Hub tokens the policy is part of the SAS.

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 device method result.

default value: 30

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 device method result.

default value: 30

az iot hub monitor-events

Monitor device telemetry & messages sent to an IoT Hub.

EXPERIMENTAL requires Python 3.5+ This command relies on and may install dependent Cython package (uamqp) upon first execution. https://github.com/Azure/azure-uamqp-python.

az iot hub monitor-events [--cg]
                          [--content-type]
                          [--device-id]
                          [--device-query]
                          [--enqueued-time]
                          [--hub-name]
                          [--interface]
                          [--login]
                          [--module-id]
                          [--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.

--interface -i

Target interface identifier to filter on. For example: dtmi:com:example:TemperatureController;1.

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

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

EXPERIMENTAL requires Python 3.4+ This command relies on and may install dependent Cython package (uamqp) upon first execution. https://github.com/Azure/azure-uamqp-python.

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.

Query an IoT Hub using a powerful SQL-like language to retrieve information regarding device and module twins, jobs and message routing. See https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-query-language for more information.

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.