A PowerShell script that delivers the steak knives too! Run ONE script to create a new group, new hub and new device with prompts for names and menus for other info. Get the required connection strings as System environment variables, and a script to regenerate them. What else? The IoT Hub SDK Quickstarts are part of the repo with some mods so that all info required is in the environemnt variables. No editing required!

NB: thi spage is the asame as the Read.Me on GitHub but has links at bottom to coming extra info.

Azure IoT Hub PowerShell Scripts

Repo: On Github as djaus2\az-iothub-ps

In the Azure IoT Hub Quickstarts. take the Quickstart link in the sidebar on left, a list of steps are repeated on most pages for creating a new Azure IoT Hub from scratch as well as for getting the required Hub connection meta-data. This meta-data is required to be provided as environment variables for the Quickstart .NET Core Sample apps, (n.b. this is a zip file), or provided as command line parameters for the apps. The Quickstart tutorials use the Azure Cli (Az Cli) in a PowerShell terminal. The UWP app Azure IoT Hub Toolbox simplifies this a little, as available as source GitHub as well as a ready to run app on the Microsoft Store, with the app’s Settings page stepping you through the Hub creation and collection of the meta-data to be used in-app. The Toolbox also requires a PowerShell Az Cli terminal as it supplies the required Az Cli commands on the clipboard.

N.b.: The .NET (Core C#) versions of the Quickstart apps are the focus here.

But wouldn’t it be nice to have ONE PowerShell script that prompts you for required information (Group, Hub name and Device name) when creating or selecting a Hub and for when collecting the required meta-data. Its output could be the required meta-data in temporary environment variables, ready for use by the Quickstarts. Look no further!

It’s here now. You run the main PowerShell script get-iothub in the PS folder. Whilst there are numerous other PowerShell script under PS in other folders, these are functions called by the main script. The script displays menus where the user makes selections or choices.

There is one other script that needs to be run once, set-path (run from the prompt in PS foloder as .\set-path ). You then can run the main script just by entering get-iothub as the PS folder is now in the System Path; but only for the life of the shell. set-path only needs to be run once for a new PowerShell terminal.

Within an Azure Subscription you have a Resource Group. An IoT Hub is an element of a Resource Group. A Device belongs to an IoT Hub.

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 :"DSHubGrp"
Hub :"DSHub"
Device :"DSHubDevice"

1. Subscription <-- Current Selection
2. Groups
3. IoT Hubs
4. Devices
5. Generate Environment Variables
6. Quickstart Apps
7. Manage App Data
8. Done


R. Reset script globals
X. Exit
Select action (number). (Default is highlighted) X To exit

The get-iothub PowerShell scipt Main Menu

Creating an IoT and subservient Device

For the Quickstarts, you need an IoT Hub and a Device from it. A Group is in a Subscription. A Hub is in a Group. A Device belongs to a Hub. Subscription-Group-Hub-Device

  • Select the Subscription to use (Normally only one option here)
  • Create a Group, or select an existing one. (Group option in Main Menu)
    • If new: Need to enter a Group name and select a location (from a menu list).
      • If Device Streaming location should be Central US
  • Create an IoT Hub or select an existing one. (Hub option in Main Menu)
    • If new: Need to enter a Hub name and select an SKU from a menu list. Default is F1. Typically select S1 if you already have one F1 Hub.
  • Create a Device or select an existing one. (Device opton in Main Menu)
    • If new: Need to enter a Device name.

The PS Script CanDos

The script can…

  • Create a new Group, IoT Hub and Device
  • Generate all of the Hub and Device connection strings required by the IoT Hub SDK for the Quickstart apps and write them as System environment variables and to a PS script to do same.
  • Place you in the folder to run a Quickstart (menu of them) with the environment variables set so as to be able to run the app/s.
    • You then just enter dontnet run to run the app/s.
    • There is also a script in some Quickstart folders to fork two processes for when a device and service are required (Eg Device Streaming).
  • The Quickstarts are part of the repository download and have been modified so that you don’t need to edit the source to include the connection strings. Connection strings are taken from environment variables.

In this series:

Coming here….Watch this space, including:

  • The IoT Hub Quickstarts (Done)
  • Connection strings and environment variables
  • Running the Quickstarts from here
  • Some extras
  • About the PowerShell scripts

Enjoy!


 TopicSubtopic
   
 This Category Links 
Category:IoT Index:IoT
  Next: > .NET Core on IoT
<  Prev:   .NET Core on IoT