I’ve added a Setup menu for downloading and installing the Azure Cli and the Azure Sphere SDK as part of the djaus2/az-iothub-ps tool (available on GitHub). I’ve encapsulated that functionality into a function for reusablity.

About az-iothub-ps

This tool is a menu driven PowerShell tool that can create an Azure Group, IoT Hub, Device and Device Provisioning Service (both linked to the hub). There is also an option to automatically create all those items from the command line. It automatically makes all of the Azure IoT Hub SDK queries.

Usage examples

    $output = "$global:ScriptDirectory\temp\azure-cli.msi"
    install-download $url $output

Installation of Az Cli using the function

    install-download $url $output

Installation of Azure Sphere SDK using the function


The function does not remove the downloaded file. That action was originally in the function but was removed as I found it generated a thread issue. The test at the end if (Test-Path $output)could support the removal.

Microsoft docs presents a PowerShell command for installing Az Cli:

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi

I found it would take a lot of time and not do anything when I had a previous installation. I found a discussion with respect to this suggesting it’s slow because it uses a lot of buffering. A suggestion was to use BITS, Background Intelligent Transfer Service to do downloads. I found this a better way to do the transfer:

    Import-Module BitsTransfer
    Start-BitsTransfer -Source $url -Destination $output

There is an option to do this synchronously, as above, or asynchronously.

Footnote: The function checks for the existence of a global PS variable $global:usePreviousDownloads. If that exists as a non-empty string then if the download file exists already, it just does the install. If not then it deletes it first.

<  Prev:   This blog site construction
 This Category Links 
Category:Coding Index:Coding
  Next: > PowerShell
<  Prev: