az iot hub device-twin

Manage IoT device twin configuration.

Commands

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 device-twin replace

Replace device twin definition with target json.

az iot hub device-twin replace --device-id
--json
[--hub-name]
[--login]
[--resource-group]

Examples

Replace device twin with file contents.

az iot hub device-twin replace -d {device_id} -n {iothub_name} -j ../mydevicetwin.json

Required Parameters

--device-id -d

Target Device.

--json -j

Json to replace existing twin with. Provide file path or raw json.

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 device-twin show

Get a device twin definition.

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

Required Parameters

--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 device-twin update

Update device twin definition.

az iot hub device-twin update --device-id
[--add]
[--force-string]
[--hub-name]
[--login]
[--remove]
[--resource-group]
[--set]

Examples

Add nested tags to device twin.

az iot hub device-twin update --device-id {device_id} --hub-name {iothub_name} --set tags='{"location":{"region":"US"}}'

Remove the 'region' property from parent 'location' property

az iot hub device-twin update --device-id {device_id} --hub-name {iothub_name} --set tags.location.region='null'

Required Parameters

--device-id -d

Target Device.

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

--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

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

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