您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure 数字孪生 CLIUse the Azure Digital Twins CLI

除了在 Azure 门户中管理 Azure 数字孪生实例以外,Azure 数字孪生还提供了一个命令行接口(CLI) ,可用于对该服务执行大多数主要操作,包括:In addition to managing your Azure Digital Twins instance in the Azure portal, Azure Digital Twins has a command-line interface (CLI) that you can use to perform most major actions with the service, including:

  • 管理 Azure 数字孪生实例Managing an Azure Digital Twins instance
  • 管理模型Managing models
  • 管理数字孪生Managing digital twins
  • 管理克隆关系Managing twin relationships
  • 配置终结点Configuring endpoints
  • 管理路由Managing routes
  • 通过基于角色的访问控制(RBAC)配置安全性Configuring security via role-based access control (RBAC)

使用(部署和验证)Uses (deploy and validate)

除了一般管理实例,CLI 也是用于部署和验证的有用工具。In addition to generally managing your instance, the CLI is also a useful tool for deployment and validation.

  • 使用控制平面命令可重复或自动部署新的实例。The control plane commands can be used to make the deployment of a new instance repeatable or automated.
  • 数据平面命令可用于快速检查实例中的值,并验证操作是否按预期完成。The data plane commands can be used to quickly check values in your instance, and verify that operations completed as expected.

获取扩展Get the extension

Azure 数字孪生命令是适用于 Azure CLI 的 Azure IoT 扩展的一部分。The Azure Digital Twins commands are part of the Azure IoT extension for Azure CLI. 您可以在 az iot 命令集: az dt中查看这些命令的参考文档。You can view the reference documentation for these commands as part of the az iot command set: az dt.

可以通过以下步骤确保具有最新版本的扩展。You can make sure you have the latest version of the extension with these steps. 可以在Azure Cloud Shell本地 Azure CLI中运行这些命令。You can run these commands in the Azure Cloud Shell or a local Azure CLI.

首先,运行此命令来查看已安装的所有扩展的列表。First, run this command to see a list of all the extensions you already have installed.

az extension list

输出是你当前拥有的所有扩展的数组。The output is an array of all the extensions you currently have. 查找每个列表项的 "name" 字段,以查看扩展的名称。Look for the "name" field for each list entry to see the names of the extensions.

使用输出确定要为扩展安装程序运行的以下哪个命令(可以运行多个)。Use the output to determine which of the following commands to run for the extension setup (you may run more than one).

  • 如果列表包含 azure-iot:你已拥有该扩展。If the list contains azure-iot: You have the extension already. 运行此命令以确保你拥有最新更新且没有其他更新可用:Run this command to make sure you have the latest update and there are no more updates available:

    az extension update --name azure-iot
    
  • 如果列表不包含 azure-iot:需要安装扩展。If the list does not contain azure-iot: You need to install the extension. 使用此命令:Use this command:

    az extension add --name azure-iot
    
  • 如果列表包含 azure-iot-cli-ext:这是该扩展的旧版本。If the list contains azure-iot-cli-ext: This is the legacy version of the extension. 一次只能安装该扩展的一个版本,因此应卸载旧扩展。Only one version of the extension should be installed at a time, so you should uninstall the legacy extension. 使用此命令:Use this command:

    az extension remove --name azure-cli-iot-ext
    

后续步骤Next steps

有关 CLI 命令的替代方法,请参阅如何使用 Api 和 Sdk 管理 Azure 数字孪生实例:For an alternative to CLI commands, see how to manage an Azure Digital Twins instance using APIs and SDKs: