Skip to content

Commit f66d8e5

Browse files
committed
powershell tabs
1 parent 75cfc9a commit f66d8e5

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

articles/iot-hub/.openpublishing.redirection.iot-hub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
},
308308
{
309309
"source_path_from_root": "/articles/iot-hub/iot-hub-create-using-cli-nodejs.md",
310-
"redirect_url": "/azure/iot-hub/iot-hub-create-using-cli",
310+
"redirect_url": "/azure/iot-hub/create-hub",
311311
"redirect_document_id": true
312312
},
313313
{

articles/iot-hub/create-hub.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: Create an Azure IoT hub
33
titleSuffix: Azure IoT Hub
4-
description: How to create, manage, and delete Azure IoT hubs through the Azure portal and CLI. Includes information about retrieving the service connection string.
4+
description: How to create, manage, and delete Azure IoT hubs through the Azure portal, CLI, and PowerShell. Includes information about retrieving the service connection string.
55
author: kgremban
66

77
ms.author: kgremban
88
ms.service: iot-hub
99
ms.topic: how-to
10-
ms.date: 07/03/2024
10+
ms.date: 07/10/2024
1111
ms.custom: ['Role: Cloud Development']
1212
---
1313

@@ -29,10 +29,20 @@ Prepare the following prerequisites, depending on which tool you use.
2929

3030
* A resource group in your Azure subscription. If you want to create a new resource group, use the [az group create](/cli/azure/group#az-group-create) command:
3131

32-
```azurecli
32+
```azurecli-interactive
3333
az group create --name <RESOURCE_GROUP_NAME> --location <REGION>
3434
```
3535

36+
### [Azure PowerShell](#tab/powershell)
37+
38+
* Azure PowerShell installed on your development machine. If you don't have Azure PowerShell, follow the steps to [Install Azure PowerShell](/powershell/azure/install-azure-powershell).
39+
40+
* A resource group in your Azure subscription. If you want to create a new resource group, use the [New-AzResourceGroup](/powershell/module/az.Resources/New-azResourceGroup) command:
41+
42+
```azurepowershell-interactive
43+
New-AzResourceGroup -Name <RESOURCE_GROUP_NAME> -Location "<REGION>"
44+
```
45+
3646
---
3747

3848
## Create an IoT hub
@@ -43,8 +53,6 @@ Prepare the following prerequisites, depending on which tool you use.
4353

4454
### [Azure CLI](#tab/cli)
4555

46-
Use the Azure CLI to create a resource group and then add an IoT hub.
47-
4856
Use the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create an IoT hub in your resource group, using a globally unique name for your IoT hub. For example:
4957

5058
```azurecli-interactive
@@ -55,6 +63,22 @@ az iot hub create --name <NEW_NAME_FOR_YOUR_IOT_HUB> --resource-group <RESOURCE_
5563

5664
The previous command creates an IoT hub in the S1 pricing tier. For more information, see [Azure IoT Hub pricing](https://azure.microsoft.com/pricing/details/iot-hub/).
5765

66+
### [Azure PowerShell](#tab/powershell)
67+
68+
Use the [New-AzIotHub](/powershell/module/az.IotHub/New-azIotHub) command to create an IoT hub in your resource group. The name of the IoT hub must be globally unique. For example:
69+
70+
```azurepowershell-interactive
71+
New-AzIotHub `
72+
-ResourceGroupName <RESOURCE_GROUP_NAME> `
73+
-Name <NEW_NAME_FOR_YOUR_IOT_HUB> `
74+
-SkuName S1 -Units 1 `
75+
-Location "<REGION>"
76+
```
77+
78+
[!INCLUDE [iot-hub-pii-note-naming-hub](../../includes/iot-hub-pii-note-naming-hub.md)]
79+
80+
The previous command creates an IoT hub in the S1 pricing tier. For more information, see [Azure IoT Hub pricing](https://azure.microsoft.com/pricing/details/iot-hub/).
81+
5882
---
5983

6084
## Connect to an IoT hub
@@ -81,15 +105,29 @@ To get the IoT Hub connection string for the **service** policy, follow these st
81105

82106
#### [Azure CLI](#tab/cli)
83107

84-
Use the [az iot hub connection-string show](/cli/azure/iot/hub/connection-string#az-iot-hub-connection-string-show) command to get a connection string for your IoT hub that adheres to the service policy:
108+
Use the [az iot hub connection-string show](/cli/azure/iot/hub/connection-string#az-iot-hub-connection-string-show) command to get a connection string for your IoT hub that grants the service policy permissions:
85109

86110
```azurecli-interactive
87-
az iot hub connection-string show --hub-name YOUR_IOT_HUB_NAME --policy-name service
111+
az iot hub connection-string show --hub-name <YOUR_IOT_HUB_NAME> --policy-name service
112+
```
113+
114+
The service connection string should look similar to the following example:
115+
116+
```text
117+
"HostName=<IOT_HUB_NAME>.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=<SHARED_ACCESS_KEY>"
118+
```
119+
120+
#### [Azure PowerShell](#tab/powershell)
121+
122+
Use the [Get-AzIotHubConnectionString](/powershell/module/az.iothub/get-aziothubconnectionstring) command to get a connection string for your IoT hub that grants the service policy permissions.
123+
124+
```azurepowershell-interactive
125+
Get-AzIotHubConnectionString -ResourceGroupName "<YOUR_RESOURCE_GROUP>" -Name "<YOUR_IOT_HUB_NAME>" -KeyName "service"
88126
```
89127

90128
The service connection string should look similar to the following example:
91129

92-
```javascript
130+
```text
93131
"HostName=<IOT_HUB_NAME>.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=<SHARED_ACCESS_KEY>"
94132
```
95133

@@ -117,21 +155,27 @@ To delete an IoT hub, run the [az iot hub delete](/cli/azure/iot/hub#az-iot-hub-
117155
az iot hub delete --name <IOT_HUB_NAME> --resource-group <RESOURCE_GROUP_NAME>
118156
```
119157

158+
### [Azure PowerShell](#tab/powershell)
159+
160+
To delete the IoT hub, use the [Remove-AzIotHub](/powershell/module/az.iothub/remove-aziothub) command.
161+
162+
```azurepowershell-interactive
163+
Remove-AzIotHub `
164+
-ResourceGroupName MyIoTRG1 `
165+
-Name MyTestIoTHub
166+
```
167+
120168
---
121169

122170
## Other tools for managing IoT hubs
123171

124172
In addition to the Azure portal and CLI, the following tools are available to help you work with IoT hubs in whichever way supports your scenario:
125173

126-
* **PowerShell cmdlets**
127-
128-
Use the [Az.IoTHub](/powershell/module/az.iothub) set of commands.
129-
130174
* **IoT Hub resource provider REST API**
131175

132176
Use the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource) set of operations.
133177

134-
* **Azure resource manager templates, Bicep, or Terraform**
178+
* **Azure resource manager templates, Bicep, or Terraform**
135179

136180
Use the [Microsoft.Devices/IoTHubs](/azure/templates/microsoft.devices/iothubs) resource type. For examples, see [IoT Hub sample templates](/samples/browse/?terms=iot%20hub&languages=bicep%2Cjson).
137181

0 commit comments

Comments
 (0)