The az-iothub-ps suite of PowerShell commands_enable a menu driven creation of Azure IoT Hubs and related entities as well as facilitating the running of Azure IoT Hub SDK .Net Core Telemetry and Device Provsioning Quickstart examples, seamlessly configured to use the hub entities. az-iothub-ps has now been extened to support all most of the steps, in a menu driven manner,required to setup and run an Azure Sphere. It can specifically generate the required app_manifest.json file for and Azure IoT Hub app.

This is a series in 4 parts:

  1. az-iothub-ps Extensions (this)
  2. DPS and IOT Hub v IOT Central with az-iothub-ps
  3. Azure Sphere and DPS (coming)
  4. Azure Sphere and IoT Central (coming)

Note that az-iothub-ps suite has been further extended and modified to include Azure IoT Central for the Azure Sphere.
See DPS and IOT Hub v IOT Central with az-iothub-ps as above.


I have an ongoing beef with many of the Azure tutorials in that they are focused upon using the Azure Portal and require you to perform a long sequence of steps through many portal pages, tabs menus etc. I came across this with the Azure IoT Hub SDK Quickstarts. Each one starts with a regurgitation of how to create an IoT Hub etc … For that I initially created the [Azure IoTHub Toolbox]{} a UWP app that guides you through that the Quickstarts, with quick and simple generation of Az Cli queries. I then developed a suite of PowerShell scripts, [az-iothub-ps GitHub repository]{https://djaus2/} that orchestartes all of this in amenu driven manner.

In the Prerelease period of Azure Sphere, I again came across portal pages brow beating. To that end I wrote a suite of batch files djaus2/AzureSphere on GitHub so simplify some of the setup of an Azure Sphere. I did say at the time that this would be ripe for a PowerShell implementation.

The az-iothub-ps suite has now been extended to support the setup of an Azure Sphere. All bar a couple of the steps covered in the Azure Sphere Setup Tutorials/Quickstarts can be actioned, again in a menu driven manner. The outcome is an Azure Sphere ready to run the AzureIoT sample in the Azure/azure-sphere-samples. That project’s is link is here: AzureIoT. The scenario is an Azure Sphere connected via DPS to an IoT Hub. (Connection to Azure Central is coming .. 2Do). The suite can besides setting up the required elements up can generate all of the required metainformation required for the Sphere app to connect to the hub, manifested as the app_manifest.son file. 😄

Using az-iothub-ps

You only need to run one script, get-iothub in the PS folder. This calls other scripts as required. You create an Azure Resource Group, an IoT Hub in that group as well as a device if using the Azure SDK Quickstarts. You can generate the hub connectivity metainformation for use by the device and service Quickstarts apps. For Az Sphere, you create a Device Provisioing Service (DPS) and link the hub to it… This is all via the get-iothub menus. No Azure Portal at this stage. As stated you can then perform most of the Azure Sphere setup steps in the suite. See below

The Main Menu

  A Z U R E  I o T  H U B     S E T U P   using PowerShell AND Azure CLI

   Subscription :"Visual Studio Ultimate with MSDN"
          Group :"StreamMeUp"
            Hub :"StreamsAway"
         Device :"StreamedDevice"
            DPS :"DPStreamMe"
         Tenant :"Sportronics"

1. Subscription
2. Groups
3. IoT Hubs
4. Devices
5. DPS
6. Environment Variables
7. Quickstart Apps
8. Manage App Data
9. All in one. Get a New: (Group ... Hub in Group ... Device for Hub)
0. Azure Sphere    <-- NEW _(Note it now has the key A. instead of 0.)_

R. Reset script globals
X. Exit

Main Menu Options

1. to 5. Enter the menu for the entities for selection, creation deletion etc.
6. Generate various enviroment variables for IoT hub connections, save delete etc.
7. Run Azure IoT Hub SDK apps using connection info from 6.
8. Store, clear and reload selected entity info
9. Create a new Group, Hub and Device in teh current Subscription in one hit
0. AzSphere commands in that context (but in PowerShell)

The Azure Sphere Menu

  • Requires a Hub and DPS to have been created and selected (See DPS menu below)
  • Requires the Hub to be connected to the DPS (See DPS Menu below)

  A Z U R E  I o T  H U B     A Z U R E  S P H E R E   using PowerShell AND Azure CLI

     Subscription :"Visual Studio Ultimate with MSDN"
            Group :"StreamMeUp"
              Hub :"StreamsAway"
              DPS :"DPStreamMe"
      Tenant Name :"Sportronics"
           Tenant :"bfbe8861-c64c-4eae-a3f2-9adf312d2efd"      
     DPS ID Scope :"0ne000E32FA"
 IOT Hub DNS Name :""
Using Short Menu

Select an    A Z U R E  S P H E R E   option

Please note that this menu has been expanded into a range of submenus.
See DPS and IOT Hub v IOT Central with az-iothub-ps

A. Enter Azure Sphere Developer Command Prompt (PS Version)
L. Login to Azure Sphere
T. Get Tenant
S. Select Tenant
D. Enable Debugging
W. Check Wifi Status
U. Check Update Status
C. Create Certificate and Enrolment group
D. Get DPS ID Scope
W. Write app_Manifest.json
B. Back

AzSphere Commands

A. Creates a PowerShell equivalent of the Azure Sphere Command Prompt (azsphere comamnd work)
L. Logs into AzSphere (Command A. does this as well)
T. Gets the current Tenant; displays it and stores its Guid for later use.
S. Can select from a number of Tenants if there is more than one.
D. Enable application debugging on the (plugged in) Azure Sphere
W. Check the Wifi Status of the plugged in Azure Sphere
U. Check the Update Status of the plugged in Azure Sphere
C. Create Certificate and Enrolment group
D. DPS ID Scope of the current DPS and store it for later use.
W. Write values from T. and D. along with the IoT Name (as an endpoint) to app_Manifest.json from the AzureIot Sample

Note that this menu requires Azure Sphere SDK to be installed but you do not run the Azure Sphere Development Command Prompt. Menu item A. above does the same actions but in PowerShell! 😄 The other commands above then use a mixture of AzSphere commands and Az CLI commands. Compare these commands with those in the Azure Sphere Documentation on Microsoft Docs. See the submenus here. Once you action these comamnds, largely in order, the last command W. will generate the required app_manifest.json file that you can copy directly into the AzureIoT sample project.😄

What’s not in get-iothub

  • Claim Your Device
    • Given the indelible manner of this command it was felt this should be done carefully, thoughtfully and not menu driven. You can’t reverse this.
    • I’m open to feedback on this. Please leave comments below. You can log in with a Social Media account.
  • Whilst menu item C. does most of the certificate downloading, creation of the new certificate, generation of the validation code etc, there is one step that has to be done in the Azure Portal. You have to action the verification certificate upload and then action the verification (press [Verify]).. Not much to do.
  • Some more advanced commands. But what is presented will get the AzureIoT sample up and running

The Device Provisioning Service Menu

  A Z U R E  I o T  H U B     D E V I C E  P R O V I S I O N I N G  S E R V I C E  (DPS) using PowerShell AND Azure CLI

   Subscription :"Visual Studio Ultimate with MSDN"
  Current Group :"StreamMeUp"
    Current Hub :"StreamsAway"  <--1
 Current Device :"StreamedDevice"
    Current DPS :"DPStreamMe"
Using Short Menu

Select a   D P S   or option       

No. of entities: 1
1. DPStreamMe <-- Current Selection

N. New  <--2
R. Refresh
S. Show
U. Unselect
D. Delete
G. Generate Env Vars for Hub Connection <--3
C. Connect Current Hub to DPS  <--4
Z. Disconnect Current Hub from DPS
B. Back

DPS Commands

N. Create a new DPS
R. Query Azure for current DPSs in the current Resource Group
S. Show details of the current DPS (Connected hubs and its ID Scope)
G. Need Hub connection string for connection to DPS, so generate.
C. Connect the current selected Hub to the current DPS
Z. Disconnect the current Hub from the current DPS

For IoT Hub - DPS connectivity (numbering as in the menu):

  1. Select the Current Hub in the IoT Hub menu
  2. Create a DPS and/or select it
  3. Generate the Hub Connection String
  4. Connect the Current Hub to the Current DPS.

 This Category Links 
Category:Azure Sphere Index:Azure Sphere
  Next: > Azure Sphere
<  Prev:   Azure Sphere Projects