How to start using Azure PowerShell in Docker

Recently I was reading that AzureRM PowerShell module is getting retried beginning of 2024. It sounds like long time, but nowadays, thing are going to fast and 2 years can fly so fast. I have chosen to install Azure PowerShell and play with it.

Important

Because Az PowerShell modules now have all the capabilities of AzureRM PowerShell modules and more, we’ll retire AzureRM PowerShell modules on 29 February 2024.

To avoid service interruptions, update your scripts that use AzureRM PowerShell modules to use Az PowerShell modules by 29 February 2024. To automatically update your scripts, follow the quickstart guide.

Microsoft

Now I installing it using docker and not on my Windows Machine. I like the fact that it can be installed and run on multiple platforms and it does not require having latest PowerShell as suggested version 7, therefore. So here is the steps how I did it:

Step1: Pull docker image

docker pull mcr.microsoft.com/azure-powershell

Step2: Deploy it in Interactive mode

docker run -it -v ~/.Azure/AzureRmContext.json:/root/.Azure/AzureRmContext.json -v ~/.Azure/TokenCache.dat:/root/.Azure/TokenCache.dat mcr.microsoft.com/azure-powershell pwsh

A a new console will show.

Step3: Sign in to Azure

First things first, I will check the version Connect-AzAccount

Now I will connect to Azure using Connect-AzAccount -UseDeviceAuthentication

This will return a link https://microsoft.com/devicelogin and device code D6XRXRPXZ, fire up the url in browser and put the device code.

Device login

here after you will be forwarded to authentication page, use your azure username and password to login with it.

Sign in page

I assume all goes well, you will get following message.

Successful login

And in your console you get your Account, Subscription Name, Tenant Id and Environment when successfully grand access.

Azure PowerShell console on Docker

Lets now for fun run few commands:

To get list of location to start with Get-AzLocation | select Location.

To get list of my resources Get-AzResourceGroup | Format-Table -GroupBy Location ResourceGroupName,ProvisioningState

Now lets create Azure Storage Account:

First we need to create resource group

New-AzResourceGroup -Name storage-rg -Location westeurope
Creating Resource Group in Azure PowerShell

Now we create Azure Storage Account

New-AzStorageAccount -ResourceGroupName storage-rg -Name stsysx001 -Location westeurope -SkuName Standard_RAGRS -Kind StorageV2
Creating Azure Storage Account in Azure PowerShell

Hence this is just a play ground, I will delete my Azure Storage Account and Resource I created before

Remove-AzStorageAccount -Name stsysx001 -ResourceGroupName storage-rg
Remove-AzResourceGroup -Name storage-rg
Deleting resource in Azure PowerShell

That is it, you can dig more in other commands, check Microsoft documentation.

Conclusion

Azure PowerShell is a powerful command line to achieve a lot of DevOps work.

Here we have learned how to deploying it on Docker, how to authenticating it and playing with it.

I am going to have a look at Azure Terraform, Microsoft Bicep and few others tools for DevOps and write some articles about them in the near future.

Leave a Comment