PowerShell, Azure and macOS? Absolutely!

Azure CLI on macOS is good for some Azure scripting but it lacks many features PowerShell can offer. Learn how to teach your Mac to talk PowerShell to your Azure environment.

Hi folks,

as you might know – I’m a PowerShell enthusiast. And I’m an Azure enthusiast. That’s why I normally use PowerShell for automating tasks around my cloud environment. Well, and I love my Macbook. With Azure CLI on macOS you can do interesting things like provisioning new VMs or get a status overview on them. But Azure CLI is not PowerShell and so it lacks some features I really appreciate.

Bildschirmfoto 2016-11-11 um 19.01.04.png
Azure CLI after executing the azure vm list command

Today I’m gonna show you the best of two worlds – how to manage your Azure environments using a Mac with Azure PowerShell cmdlets on macOS. How it works? Learn it here!

Before starting be aware that .Net Core still is in preview and that the PowerShell modules mentioned in this blog post come with limited functionality and only few cmdlets compared to the modules you can run using a Windows machine. If you want to use PowerShell in productive environments I still suggest to leverage PowerShell on Windows.

There are several steps to do in order to be able to manage Azure via PowerShell on your Mac:

  1. Install PowerShell
  2. Install .NET Core
  3. Install the AzureRm.NetCore.Preview module

1. Install PowerShell

This might be the easiest part of your journey. Simply browse to the PowerShell project’s releases page and select the .pkg-file for download. Make sure not to install PowerShell 6.0.0. Alpha 12, as this version currently has issues with installing PowerShell modules. I’ve proved Alpha 9 through 11 to work whereas I had the same issues stated in the GitHub discussion.

Bildschirmfoto 2016-11-11 um 21.00.06.png
Download the .pkg-file

To install the PowerShell package you either have to change your Mac’s security settings as the package is untrusted or you right-click the package and select “open”. After installation you can start PowerShell in your terminal session by simply calling “PowerShell”.

PowerShell on MacOS 10.12.1

2. Install .NET Core

In order to get Azure modules installed and running you need to install .NET Core first. There is a very easy manual provided by Microsoft. You need to update your SSL client using the following bash commands:

brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

After that you can download the official installer of .NET Core for macOS. After installation you need to initialize some code. You can do that by using the following commands:

mkdir hwapp
cd hwapp
dotnet new
dotnet restore
dotnet run
Bildschirmfoto 2016-11-11 um 19.12.03.png
Initialize .NET Core on macOS

Done. Your all set up to install the AzureRM.NetCore.Preview PowerShell module package.

3. Install AzureRM.NetCore.Preview PowerShell module package

To download and install the Azure PowerShell module package use the following PowerShell code:

Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination /usr/local/microsoft/powershell/6.0.0-alpha.11/Modules

With the cmdlet

get-module -listAvailable

you can test if the installation was successful.

Bildschirmfoto 2016-11-11 um 21.13.46.png
Get-Module -ListAvailable proves: AzureRm.* modules are installed

Now import the modules and start accessing your Azure Resource Manager subscription.

Get-Module -ListAvailable AzureRm.* | Import-Module

You are prompted to browse to https://aka.ms/devicelogin and to enter the provided code and your Azure admin credentials. That’s it.

Bildschirmfoto 2016-11-11 um 21.27.34.png
Azure Resource Manager cmdlets on macOS

You see, if you know what to do, it is pretty easy to get Azure PowerShell cmdlets running on macOS. If you love PowerShell, Azure and Macs just like me there’s no way to get around!

Author: Tom Janetscheck

Cloud Security Enthusiast | Security Advocate

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: