Proposed Pull Request Change

title description author ms.author ms.date ms.topic ms.service services ms.subservice ms.custom
Quickstart - Set up Azure IoT Hub Device Provisioning Service using Azure CLI Quickstart - Set up the Azure IoT Hub Device Provisioning Service (DPS) using Azure CLI cwatson-cat cwatson 08/12/2025 quickstart azure-iot-hub iot-dps azure-iot-hub-dps ['mvc', 'devx-track-azurecli', 'mode-api', 'sfi-image-nochange', 'sfi-ropc-nochange']
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: Quickstart - Set up Azure IoT Hub Device Provisioning Service using Azure CLI description: Quickstart - Set up the Azure IoT Hub Device Provisioning Service (DPS) using Azure CLI author: cwatson-cat ms.author: cwatson ms.date: 08/12/2025 ms.topic: quickstart ms.service: azure-iot-hub services: iot-dps ms.subservice: azure-iot-hub-dps ms.custom: - mvc - devx-track-azurecli - mode-api - sfi-image-nochange - sfi-ropc-nochange --- # Quickstart: Set up the IoT Hub Device Provisioning Service with Azure CLI The Azure CLI is used to create and manage Azure resources from the command line or in scripts. This quickstart details using the Azure CLI to create an IoT hub and an IoT Hub Device Provisioning Service instance, and to link the two services together. [!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)] > [!IMPORTANT] > Both the IoT hub and the provisioning service you create in this quickstart are publicly discoverable as DNS endpoints. Make sure to avoid any sensitive information if you decide to change the names used for these resources. > [!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment.md)] ## Create a resource group Create a resource group with the [az group create](/cli/azure/group#az-group-create) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *my-sample-resource-group* in the *westus* location. ```azurecli-interactive az group create --name my-sample-resource-group --location westus ``` > [!TIP] > The example creates the resource group in the West US location. You can view a list of available locations by running the command `az account list-locations -o table`. > > ## Create an IoT hub Create an IoT hub with the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command. The following example creates an IoT hub named *my-sample-hub* in the *westus* location. An IoT hub name must be globally unique in Azure, so either add a unique prefix or suffix to the example name or choose a new name altogether. Make sure your name follows proper naming conventions for an IoT hub: it should be 3-50 characters in length, and can contain only upper or lower case alphanumeric characters or hyphens ('-'). ```azurecli-interactive az iot hub create --name my-sample-hub --resource-group my-sample-resource-group --location westus ``` ## Create a Device Provisioning Service instance Create a Device Provisioning Service instance with the [az iot dps create](/cli/azure/iot/dps#az-iot-dps-create) command. The following example creates a Device Provisioning Service instance named *my-sample-dps* in the *westus* location. You must also choose a globally unique name for your own instance. Make sure it follows proper naming conventions for an IoT Hub Device Provisioning Service: it should be 3-64 characters in length and can contain only upper or lower case alphanumeric characters or hyphens ('-'). ```azurecli-interactive az iot dps create --name my-sample-dps --resource-group my-sample-resource-group --location westus ``` > [!TIP] > The example creates the provisioning service in the West US location. You can view a list of available locations by running the command `az provider show --namespace Microsoft.Devices --query "resourceTypes[?resourceType=='ProvisioningServices'].locations | [0]" --out table` or by going to the [Azure Status](https://azure.microsoft.com/status/) page and searching for "Device Provisioning Service". In commands, locations can be specified either in one word or multi-word format; for example: westus, West US, WEST US, etc. The value isn't case sensitive. If you use multi-word format to specify location, enclose the value in quotes; for example, `--location "West US"`. > > For resiliency and reliability, we recommend deploying to one of the regions that support [Availability Zones](iot-dps-ha-dr.md). ## Get the connection string for the IoT hub You need your IoT hub's connection string to link it with the Device Provisioning Service. Use the [az iot hub connection-string show](/cli/azure/iot/hub/connection-string#az-iot-hub-connection-string-show) command to get the connection string and use its output to set a variable used later, when you link the two resources. The following example sets the *hubConnectionString* variable to the value of the connection string for the primary key of the hub's *iothubowner* policy (the `--policy-name` parameter can be used to specify a different policy). Trade out *my-sample-hub* for the unique IoT hub name you chose earlier. The command uses the Azure CLI [query](/cli/azure/query-azure-cli) and [output](/cli/azure/format-output-azure-cli#tsv-output-format) options to extract the connection string from the command output. ```azurecli-interactive hubConnectionString=$(az iot hub connection-string show --name my-sample-hub --key primary --query connectionString -o tsv) ``` You can use the `echo` command to see the connection string. ```azurecli-interactive echo $hubConnectionString ``` > [!NOTE] > These two commands are valid for a host running under Bash. > > If you're using a local Windows/CMD shell or a PowerShell host, modify the commands to use the correct syntax for that environment. > > If you're using Azure Cloud Shell, check that the environment drop-down on the left side of the shell window says **Bash**. > ## Link the IoT hub and the provisioning service Link the IoT hub and your provisioning service with the [az iot dps linked-hub create](/cli/azure/iot/dps/linked-hub#az-iot-dps-linked-hub-create) command. The following example links an IoT hub named *my-sample-hub* in the *westus* location and a Device Provisioning Service named *my-sample-dps*. Trade out these names for the unique IoT hub and Device Provisioning Service names you chose earlier. The command uses the connection string for your IoT hub that was stored in the *hubConnectionString* variable in the previous step. ```azurecli-interactive az iot dps linked-hub create --dps-name my-sample-dps --resource-group my-sample-resource-group --connection-string $hubConnectionString --location westus ``` The command might take a few minutes to complete. ## Verify the provisioning service Get the details of your provisioning service with the [az iot dps show](/cli/azure/iot/dps#az-iot-dps-show) command. The following example gets the details of a provisioning service named *my-sample-dps*. Trade out this name for your own Device Provisioning Service name. ```azurecli-interactive az iot dps show --name my-sample-dps ``` The linked IoT hub is shown in the *properties.iotHubs* collection. :::image type="content" source="./media/quick-setup-auto-provision-cli/verify-provisioning-service.png" alt-text="Screen capture of an Azure Cloud Shell window, highlighting the properties.iotHubs collection displayed in the output of the az iot dps show command."::: ## Clean up resources Other quickstarts in this collection build upon this quickstart. If you plan to continue on to work with subsequent quickstarts or with the tutorials, don't clean up the resources created in this quickstart. If you don't plan to continue, you can use the following commands to delete the provisioning service, the IoT hub, or the resource group and all of its resources. Replace the names of the resources included in the following commands with the names of your own resources. To delete the provisioning service, run the [az iot dps delete](/cli/azure/iot/dps#az-iot-dps-delete) command: ```azurecli-interactive az iot dps delete --name my-sample-dps --resource-group my-sample-resource-group ``` To delete the IoT hub, run the [az iot hub delete](/cli/azure/iot/hub#az-iot-hub-delete) command: ```azurecli-interactive az iot hub delete --name my-sample-hub --resource-group my-sample-resource-group ``` To delete a resource group and all its resources, run the [az group delete](/cli/azure/group#az-group-delete) command: ```azurecli-interactive az group delete --name my-sample-resource-group ``` ## Next steps In this quickstart, you deployed an IoT hub and a Device Provisioning Service instance, and linked the two resources. To learn how to use this setup to provision a device, continue to the quickstart for creating a device. > [!div class="nextstepaction"] > [Quickstart: Provision a simulated symmetric key device](./quick-create-simulated-device-symm-key.md)
Success! Branch created successfully. Create Pull Request on GitHub
Error: