Share via


az iot hub state

Note

This reference is part of the azure-iot extension for the Azure CLI (version 2.59.0 or higher). The extension will automatically install the first time you run an az iot hub state command. Learn more about extensions.

This command group is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus

Manage the state of an IoT Hub.

For more information, see aka.ms/aziotcli-iot-hub-state.

Commands

Name Description Type Status
az iot hub state export

Export the state of an IoT Hub to a file.

Extension Experimental
az iot hub state import

Import a Hub state from a file to an IoT Hub.

Extension Experimental
az iot hub state migrate

Migrate the state of one hub to another hub without saving to a file.

Extension Experimental

az iot hub state export

Experimental

Command group 'iot hub state' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus

Export the state of an IoT Hub to a file.

By default, the exported state will include: arm template for hub, hub configurations (including ADM configurations and edge deployments), device information (including device identites, device twins, module identities and module twins).

For more information, see aka.ms/aziotcli-iot-hub-state.

az iot hub state export --state-file
                        [--aspects {arm, configurations, devices}]
                        [--auth-type {key, login}]
                        [--hub-name]
                        [--login]
                        [--replace]
                        [--resource-group]

Examples

Export the supported state of the specified hub to the specified file.

az iot hub state export -n {iothub_name} -f {state_filename}

Export the supported state of the specified hub to the specified file, overwriting the file contents.

az iot hub state export -n {iothub_name} -f {state_filename} -r

Export only the devices and configurations of the specified hub to the specified file.

az iot hub state export -n {iothub_name} -f {state_filename} --aspects devices configurations

Required Parameters

--state-file -f

The path to the file where the state information will be stored.

Optional Parameters

The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.

--aspects

Hub Aspects (space-separated).

Property Value
Accepted values: arm, configurations, devices
--auth-type

Indicates whether the operation should auto-derive a policy key or use the current Azure AD session. If the authentication type is login and the resource hostname is provided, resource lookup will be skipped unless needed.You can configure the default using az configure --defaults iothub-data-auth-type={auth-type-value}.

Property Value
Parameter group: Access Control Arguments
Default value: key
Accepted values: key, login
--hub-name -n

IoT Hub name or hostname. Required if --login is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--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. Required if --hub-name is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--replace -r

If this flag is set, then the command will overwrite the contents of the output file.

Property Value
Default value: False
--resource-group -g

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

Global Parameters
--debug

Increase logging verbosity to show all debug logs.

Property Value
Default value: False
--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

Property Value
Default value: False
--output -o

Output format.

Property Value
Default value: json
Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--verbose

Increase logging verbosity. Use --debug for full debug logs.

Property Value
Default value: False

az iot hub state import

Experimental

Command group 'iot hub state' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus

Import a Hub state from a file to an IoT Hub.

If the arm aspect is specified, the hub will be created if it does not exist.

By default, the imported state will include: arm template for hub, hub configurations (including ADM configurations and edge deployments), device information (including device identites, device twins, module identities and module twins).

For imported endpoints with system assigned identity authentication, the specified hub must have the correct permissions. Otherwise the command will fail.

Private endpoints will be ignored in the import process.

For more information, see aka.ms/aziotcli-iot-hub-state.

az iot hub state import --state-file
                        [--aspects {arm, configurations, devices}]
                        [--auth-type {key, login}]
                        [--hub-name]
                        [--login]
                        [--replace]
                        [--resource-group]

Examples

Import the supported state from the specified file to the specified hub.

az iot hub state import -n {iothub_name} -f {state_filename}

Import the supported state from the specified file to the specified hub, overwriting the previous state of the hub. All certificates, configurations, and devices will be deleted before the new state is uploaded.

az iot hub state import -n {iothub_name} -f {state_filename} -r

Import only the arm template from the specified file to the specified hub. Note that this will create a new hub if it does not exist. The file may contain the devices and configurations but those will be ignored.

az iot hub state import -n {iothub_name} -g {resource_group} -f {state_filename} --aspects arm

Import only the devices and configurations from the specified file to the specified hub. Note that this will NOT create a new hub if it does not exist and the command will fail. The file may contain the arm template but that will be ignored.

az iot hub state import -n {iothub_name} -f {state_filename} --aspects devices configurations

Required Parameters

--state-file -f

The path to the file where the state information will be stored.

Optional Parameters

The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.

--aspects

Hub Aspects (space-separated).

Property Value
Accepted values: arm, configurations, devices
--auth-type

Indicates whether the operation should auto-derive a policy key or use the current Azure AD session. If the authentication type is login and the resource hostname is provided, resource lookup will be skipped unless needed.You can configure the default using az configure --defaults iothub-data-auth-type={auth-type-value}.

Property Value
Parameter group: Access Control Arguments
Default value: key
Accepted values: key, login
--hub-name -n

IoT Hub name or hostname. Required if --login is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--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. Required if --hub-name is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--replace -r

If this flag is set, then the command will delete the current devices, configurations, and certificates of the destination hub.

Property Value
Default value: False
--resource-group -g

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

Global Parameters
--debug

Increase logging verbosity to show all debug logs.

Property Value
Default value: False
--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

Property Value
Default value: False
--output -o

Output format.

Property Value
Default value: json
Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--verbose

Increase logging verbosity. Use --debug for full debug logs.

Property Value
Default value: False

az iot hub state migrate

Experimental

Command group 'iot hub state' is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus

Migrate the state of one hub to another hub without saving to a file.

If the arm aspect is specified, the hub will be created if it does not exist.

By default, the migrated state will include: arm template for hub, hub configurations (including ADM configurations and edge deployments), device information (including device identites, device twins, module identities and module twins).

For migrated endpoints with system assigned identity authentication, the specified hub must have the correct permissions. Otherwise the command will fail.

Private endpoints will be ignored in the migration process.

If you have trouble migrating, please use the export and import commands to have a file as a backup.

For more information, see aka.ms/aziotcli-iot-hub-state.

az iot hub state migrate [--aspects {arm, configurations, devices}]
                         [--auth-type {key, login}]
                         [--destination-hub --dh]
                         [--destination-hub-login --dl]
                         [--destination-resource-group --dg]
                         [--og --origin-resource-group]
                         [--oh --origin-hub]
                         [--ol --origin-hub-login]
                         [--replace]

Examples

Migrate the supported state of the origin hub to the destination hub.

az iot hub state migrate --destination-hub {dest_hub_name} --origin-hub {orig_hub_name}

Migrate the supported state of the origin hub to the destination hub, overwriting the previous state of the hub. All certificates, configurations, and devices in the destination hub will be deleted before the new state is uploaded.

az iot hub state migrate --destination-hub {dest_hub_name} --origin-hub {orig_hub_name} -r

Migrate only the arm template from the origin hub to the destination hub. Note that this will create a new hub if the destination hub does not exist. The origin hub may contain the devices and configurations but those will be ignored.

az iot hub state migrate --destination-hub {dest_hub_name} --destination-resource-group {dest_hub_resource_group} --origin-hub {orig_hub_name} --aspects arm

Migrate only the devices and configurations from the origin hub to the destination hub. Note that this will NOT create a new hub if the destination hub does not exist and the command will fail. The arm template for the origin hub will be ignored.

az iot hub state migrate --destination-hub {dest_hub_name} --origin-hub {orig_hub_name} --aspects devices configurations

Optional Parameters

The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.

--aspects

Hub Aspects (space-separated).

Property Value
Accepted values: arm, configurations, devices
--auth-type

Indicates whether the operation should auto-derive a policy key or use the current Azure AD session. If the authentication type is login and the resource hostname is provided, resource lookup will be skipped unless needed.You can configure the default using az configure --defaults iothub-data-auth-type={auth-type-value}.

Property Value
Parameter group: Access Control Arguments
Default value: key
Accepted values: key, login
--destination-hub --dh

Name of IoT Hub to which the origin hub state will be copied to.

Property Value
Parameter group: IoT Hub Identifier Arguments
--destination-hub-login --dl

This command supports an entity connection string with rights to perform action on the destination hub. Use to avoid session login via az login for this IoT Hub instance. If both an entity connection string and name are provided the connection string takes priority. Required if --destination-hub is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--destination-resource-group --dg

Name of resource group of the IoT Hub to which the origin hub state will be copied to. If not provided, will use the origin IoT Hub's resource group.

Property Value
Parameter group: IoT Hub Identifier Arguments
--og --origin-resource-group

Name of resource group of the IoT Hub which will be copied.

Property Value
Parameter group: IoT Hub Identifier Arguments
--oh --origin-hub

Name of IoT Hub which will be copied.

Property Value
Parameter group: IoT Hub Identifier Arguments
--ol --origin-hub-login

This command supports an entity connection string with rights to perform action on the origin hub. Use to avoid session login via az login for this IoT Hub instance. If both an entity connection string and name are provided the connection string takes priority. Required if --origin-hub is not provided.

Property Value
Parameter group: IoT Hub Identifier Arguments
--replace -r

If this flag is set, then the command will delete the current devices, configurations, and certificates of the destination hub.

Property Value
Default value: False
Global Parameters
--debug

Increase logging verbosity to show all debug logs.

Property Value
Default value: False
--help -h

Show this help message and exit.

--only-show-errors

Only show errors, suppressing warnings.

Property Value
Default value: False
--output -o

Output format.

Property Value
Default value: json
Accepted values: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath query string. See http://jmespath.org/ for more information and examples.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--verbose

Increase logging verbosity. Use --debug for full debug logs.

Property Value
Default value: False