In this post, I will discuss installing and configuring PowerShell for Azure Stack and required tools/modules so that we can leverage existing AzureRM cmdlets for further configuration and management tasks. That will also show you the real consistency between Azure and Azure Stack in terms of PowerShell cmdlets.
Follow me:
Latest posts by Anil Erduran (see all)

In my previous blog on Azure Stack, we discussed about installing Microsoft Azure Stack (MAS) TP2 on a nested Hyper-V environment. Thanks to recent improvements in Hyper-V, nested virtualization is now officially supported in Windows 10 and Windows Server 2016. Having nested virtualization is a great chance to test and experience Azure Stack environment in your home lab or even on a desktop PC without needing high-end hardware components.

Now that Azure Stack is deployed, we can think about creating a storage account (blob or table), firing up our very first virtual machine, playing with tenants/plans, and maybe publishing some more content to the existing Azure Stack marketplace.

But before taking the next step, we need our environment ready to accept PowerShell connections. We need additional modules and tools to run existing AzureRM commands targeting an Azure Stack local subscription.

With Windows Management Framework 5.0, now there is a great way to share your PowerShell work with other community members in a pre-defined format so that anyone can easily use these in their organization. Using new package manager called "PowerShellGet," you can search public or private repositories to find PowerShell modules you need. By default, there is one repository called PSGallery, which is a public Microsoft supported place. You can find a bunch of PS commands and DSC resources available there.

PowerShell Gallery

PowerShell Gallery

You can see available repositories by using the Get-PSRepository command.

List available repositories

List available repositories

I want to discuss this repository first because some required modules, most importantly popular AzureRM package, are part of this repository. They can be downloaded using the Install-Module command.

Once your Azure Stack installation is completed, you can RDP to your MAS-CON01 server, open PowerShell with administrative rights, and use following command to install AzureRM module from PowerShell Gallery.

Install-Module -Name AzureRM -RequiredVersion 1.2.6 -Scope CurrentUser
Install AzureRM module

Install AzureRM module

You can now list all available commands imported along with this module using Get-Command cmdlet:

Get-Command -Module AzureRM.Azure StackAdmin
Get commands for AzureRM module

Get commands for AzureRM module

Now we have required cmdlets related to Azure Resource Manager tasks such as creating a Resource Group or blob containers and importing Marketplace Gallery items into Azure Stack, just like we have been doing on public Azure for a while.

But if you try to use any of the AzureRM cmdlets on Azure Stack box, you will encounter an error telling you that you first need to associate your existing PowerShell session with a subscription.

No subscription error

No subscription error

For Azure Stack, our subscription name is "Default Provider Subscription," but the AzureRM module does not include required cmdlets to create a connection to an Azure Stack endpoint.

For this, we need to download an additional module called Azure Stack-Tools.

Here is a quick way of obtaining this module:

Invoke-WebRequest Stack-Tools/archive/ -OutFile
Expand-Archive -DestinationPath . -Force

These commands will download Azure Stack-Tools from the GitHub repository and then expand it to the current directory.

There are many functions you can use in this module. The most crucial one is to establish a connection to Azure Stack environment. First, navigate to the "Connect" folder under the module directory and import the Azure Stack.Connect module using:

Import-Module .\Azure Stack.Connect.psm1

Then you can use Add-Azure StackAzureRmEnvironment to target your AzureRM cmdlets to your Azure Stack subscription. You need to provide an additional parameter called AadTenant, which should be set to the Azure Active Directory name you have used for the installation script.

Add-Azure StackAzureRmEnvironment -AadTenant "<mydirectory>"

Here we go. Now our Azure Stack environment is registered.

Register Azure Stack environment

Register Azure Stack environment

Now you can target AzureRM cmdlets to our one and only Azure Stack instance using the Add-AzureRmAccount cmdlet.

Add-AzureRmAccount -EnvironmentName Azure Stack -TenantId $AadTenant
Target AzureRM cmdlets to Azure Stack

Target AzureRM cmdlets to Azure Stack

Let’s try the same command again to create a new resource group.

Creating a new resource grou

Creating a new resource grou

Cool. Now I can use native AzureRM cmdlets to take actions on my local Azure Stack instance.

If you already read my Azure Storage Services article series, we have used different AzureRM cmdlets to list or take actions on Azure storage resources. As Azure Stack is also a copy of public Azure in your datacenter, we should be able to do same.

Let me try to list all local storage accounts available:

Get-AzureStorageAccount | Format-Table -Property *
List available storage accounts

List available storage accounts

Except for the first one, these are default storage accounts created by the installation script.

Let’s try to create a new container for one of our storage accounts and then upload a blob content using AzureRM cmdlets.

The following command will create a storage account context for my storage account:blob1 so that we can use it for further storage-related tasks.

$Context = Set-AzureRmStorageAccount -ResourceGroupName MASRS01 -Name blob1 -Type Standard_LRS

Actual storage context is inside the .context property of the $context variable.

Storage context details

Storage context details

Creating a new container:

$StorageContainerName = "tempfiles"
New-AzureStorageContainer -Name $StorageContainerName -Permission Container -Context $Context.Context

I created a new container called "tempfiles" and set the permission to "container," which provides public access. You can see the newly created container on the Azure Stack portal.

Container details on portal

Container details on portal

We can also leverage the Set-AzureStorageBlobContent command to upload any local files to the blob storage.

Set-AzureStorageBlobContent -Container $StorageContainerName -File "C:\Users\FabricAdmin\Desktop\Output\Contoso.SimpleVMTemplate.1.0.0.azpkg" -Context $Context.Context

I’m simply trying to upload "Contoso.SimpleVMTemplate.1.0.0.azpkg," which is a marketplace compressed template file.

Uploading blob content

Uploading blob content

You can also use Get-AzureStorageBlobContent to list contents for a specific blob container:

Subscribe to 4sysops newsletter!

Get-AzureStorageBlob -Container $StorageContainerName -Context $Context.Context | Get-AzureStorageBlobContent | Select -Property *
Getting blob content

Getting blob content

Azure Stack is the copy of Azure in your datacenter. That consistency makes a bunch of different scenarios available. This post was a glimpse of installing and configuring PowerShell environment for Azure Stack. Now you are ready to use native AzureRM commands to target your local Azure Stack environment.

  1. Avatar
    Itamar 7 years ago

    in your home lab” but Azure stack need 96 G 

    Can I install on 32 G or 16 G ?




  2. Avatar Author

    Yes. See my previous post on how to install MAS on a nested VM and change installation requirements.

  3. Avatar
    Ieawyan Roz 7 years ago

    Great insight here.

Leave a reply

Your email address will not be published. Required fields are marked *


© 4sysops 2006 - 2023


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account