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.
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:
- Install PowerShell
- Install .NET Core
- 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.
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”.
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
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
you can test if the installation was successful.
Now import the modules and start accessing your Azure Resource Manager subscription.
Get-Module -ListAvailable AzureRm.* | Import-Module Login-AzureRmAccount
You are prompted to browse to https://aka.ms/devicelogin and to enter the provided code and your Azure admin credentials. That’s it.
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!