Install and configure PowerShell for Azure Stack

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.
Profile gravatar of Anil Erduran
Follow me:

Anil Erduran

Anil Erduran is a principal consultant and subject matter expert for Hitachi Data Systems EMEA, based in London, UK. He is also a dual category Microsoft Most Valuable Professional in Cloud and Datacenter Management and Microsoft Azure. Anil can be found on Twitter @anil_erduran.
Profile gravatar of Anil Erduran
Follow me:

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 AzureRM module

Install AzureRM module

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

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:

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:

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.

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.

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:

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.

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

Storage context details

Storage context details

Creating a new container:

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.

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:

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.

Take part in our competition and win $100!

Related Posts

3 Comments
  1. avatar
    Itamar 6 months ago

    "in your home lab" but Azure stack need 96 G 

    Can I install on 32 G or 16 G ?

     

    Tnx.

    Itamar

    0
  2. Profile gravatar of Anil Erduran Author
    Anil Erduran 6 months ago

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

    0
  3. avatar
    Ieawyan Roz 5 months ago

    Great insight here.

    0

Leave a reply

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

*

CONTACT US

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

Sending
© 4sysops 2006 - 2017
Do NOT follow this link or you will be banned from the site!

Log in with your credentials

or    

Forgot your details?

Create Account